sudo apt update && sudo apt upgrade -y
wget https://dev.mysql.com/get/mysql-apt-config_0.8.34-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.34-1_all.deb
sudo apt update
(安装时选择MySQL版本,如8.0)sudo apt install mysql-server
(安装过程中可设置root密码,或后续通过mysql_secure_installation
配置)sudo mysql_secure_installation
sudo systemctl start mysql
sudo systemctl enable mysql # 开机自启
sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf
bind-address
改为0.0.0.0
port
参数sudo systemctl restart mysql
-- 登录MySQL后执行
CREATE USER 'remote_user'@'%' IDENTIFIED BY '强密码';
GRANT ALL PRIVILEGES ON *.* TO 'remote_user'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
mysql -u root -p
sudo systemctl status mysql
sudo ufw allow 3306/tcp # 允许MySQL端口
validate_password
插件强化密码安全。mysqldump -u root -p --all-databases > backup.sql
。参考来源: