安装
sudo apt-get update
sudo apt-get install mysql-server
设置root密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';
FLUSH PRIVILEGES;
添加用户并设置远程可访问
添加用户并赋予权限
CREATE USER 'remote_user'@'%' IDENTIFIED BY 'Password@123';
GRANT ALL PRIVILEGES ON *.* TO 'remote_user'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
编辑配置文件
sudo nano /etc/mysql/my.cnf
修改 bind-address 配置项
[mysqld]
bind-address = 0.0.0.0
重启mysql
sudo service mysql restart
配置防火墙
sudo ufw allow 3306/tcp