2. 在 Ubuntu 上保护 MySQL

01 MySQL安装自带一个名为mysql_secure_installation的脚本,可以让你轻松提高MySQL服务器的安全性,所以运行以下命令:

$sudo mysql_secure_installation

02 系统会要求我们配置VALIDATE PASSWORD PLUGIN,用于测试MySQL用户密码的强度并提高安全性。

Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No:

如果要设置验证密码插件或者任何其他键以进入下一步,请按“y”。

03 密码验证策略分为低、中、强三个级别。

There are three levels of password validation policy:
LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:

输入“2”进行强密码验证。

04 接下来,我们将被要求为 MySQL root 用户设置密码。

Please set the password for root here.

如果我们设置了验证密码插件,脚本将向我们显示新密码的强度。
输入“y”以确认密码。

Estimated strength of the password: 100 
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :

05 接下来,我们将被要求删除匿名用户,限制 root 用户访问本地机器,删除测试数据库,并重新加载权限表。
我们应该对所有问题都回答“y”。

3. 在 Ubuntu 上连接 MySQL 服务器

在 MySQL 8.0 中,root 用户默认由 auth_socket插件验证。
因此,使用以下命令以 root 身份连接到 MySQL 服务器:

$sudo mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.20-0ubuntu0.20.04.1 (Ubuntu)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
如何在 Ubuntu 20.04 上安装 MySQL

MySQL 是最受欢迎的开源关系数据库管理系统,它得到了庞大而活跃的开源开发人员社区的支持。

1. 在 Ubuntu 上安装 MySQL

01 首先将软件包更新到可用的最新版本。

$sudo apt update
$sudo apt upgrade

02 在 Ubuntu 20.04 中 MySQL 8 默认包含在 Focal onitroada 存储库中,因此我们可以使用 apt install命令轻松安装它:

$sudo apt install mysql-server

03 安装完成后,MySQL服务会自动启动。
要验证 MySQL 服务器是否正在运行,执行:

$sudo service mysql status
 ● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2016-05-29 20:13:18 UTC; 1min 4s ago
   Main PID: 3333 (mysqld)
     Status: "Server is operational"
      Tasks: 38 (limit: 2010)
     Memory: 322.9M
     CGroup: /system.slice/mysql.service
             └─3333 /usr/sbin/mysqld
日期:2020-06-02 22:18:16 来源:oir作者:oir