在写作这篇文章的时候,Ubuntu 源仓库中最新的 MySQL 版本号是 MySQL 8.0。想要安装它,运行下面的命令:
1
2
sudo apt update
sudo apt install mysql-server
一旦安装完成,MySQL 服务将会自动启动。想要验证 MySQL 服务器正在运行,输入:
1
sudo systemctl status mysql
输出应该显示服务已经被启用,并且正在运行:
1
2
3
4
5
6
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-04-28 20:59:52 UTC; 10min ago
Main PID: 8617(mysqld)
Status: "Server is operational"
...
保护加固 MySQL
MySQL 安装文件附带了一个名为mysql_secure_installation的脚本,它允许你很容易地提高数据库服务器的安全性。
不带参数运行这个脚本:
1
sudo mysql_secure_installation
你将会被要求配置VALIDATE PASSWORD PLUGIN,它被用来测试 MySQL 用户密码的强度,并且提高安全性:
1
2
3
4
5
6
7
8
9
10
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
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
下一次被提示时,你将被要求为 MySQL root 用户设置一个密码:
1
2
3
4
5
6
Please set the password for root here.
New password:
Re-enter new password:
如果你设置了验证密码插件,这个脚本将会显示你的新密码强度。输入y确认密码:
1
2
Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.19-0ubuntu5 (Ubuntu)
Copyright (c) 2000, 2020, 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>
如果你想以 root 身份登录 MySQL 服务器,使用其他的程序,例如 phpMyAdmin,你有两个选择。
预览: