在Ubuntu上进行MySQL安全设置,可以遵循以下步骤:
首先,确保系统已经更新到最新版本,然后使用以下命令安装MySQL服务器:
sudo apt update
sudo apt install mysql-server
安装完成后,运行 mysql_secure_installation
脚本进行安全设置:
sudo mysql_secure_installation
y
删除所有匿名用户。y
禁止root用户通过远程连接登录。y
删除 test
数据库。y
重新加载权限表以保存所有更改。检查并更改root用户的认证方式:
SELECT user, authentication_string, plugin, host FROM mysql.user;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_new_password';
FLUSH PRIVILEGES;
创建新用户并授予权限,遵循最小权限原则:
CREATE USER 'newuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
为MySQL配置SSL加密以保护数据传输安全:
sudo apt install mysql-server openssl
openssl genpkey -algorithm rsa -out mysql_private.key -aes256
openssl req -new -key mysql_private.key -out mysql_csr.csr
openssl x509 -req -days 365 -in mysql_csr.csr -signkey mysql_private.key -out mysql_certificate.crt
编辑MySQL配置文件(通常是 /etc/mysql/mysql.conf.d/mysqld.cnf
或 /etc/my.cnf
),在 [mysqld]
部分添加或修改以下行:
ssl-ca /path/to/mysql_certificate.crt
ssl-cert /path/to/mysql_certificate.crt
ssl-key /path/to/mysql_private.key
sudo systemctl restart mysql
通过以上步骤,可以有效地增强Ubuntu上MySQL数据库的安全性。