Install MySQL on Ubuntu
Ubuntu: 18.04
MySQL: 5.7
Install MySQL
sudo apt install mysql-server
執行 MySQL secure script,啟用相關安全設定
sudo mysql_secure_installation
mysql_secure_installation
可以設定 密碼強度控制
、拒絕遠端 root 登入
等等的安全性設定。
Notice:如果你可能還需要透過
root
帳號做事情(例如透過 phpMyAdmin 操作),那就要更換一下 root 帳號的認證模式並設定密碼。
修改 root 密碼
進入 MySQL command line
sudo mysql
查詢帳號狀態
mysql>SELECT user,authentication_string,plugin,host FROM mysql.user;
+------------------+-------------------------------------------+-----------------------+-----------+
| user | authentication_string | plugin | host |
+------------------+-------------------------------------------+-----------------------+-----------+
| root | | auth_socket | localhost |
| mysql.session | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| mysql.sys | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE | mysql_native_password | localhost |
| debian-sys-maint | *E1CA7F7DEA9340570136C36064CA2BA275014159 | mysql_native_password | localhost |
+------------------+-------------------------------------------+-----------------------+-----------+
修改 root
認證模式並更改密碼
# 換成使用 mysql_native_password 認證
mysql>ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
# Reload 權限設定
mysql>FLUSH PRIVILEGES;