使用root用户登录mysql
mysql -u root -p
新增一个用户
use mysql;
CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';
给新用户添加权限
GRANT ALL PRIVILEGES ON *.* TO 'username'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
flush privileges;
quit
修改mysql配置文件
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
找到bind-address = 127.0.0.1
修改为 bind-address = 0.0.0.0
:wq
重启mysql
service mysql restart
开放3306端口
服务器需要配置安全组规则
有防火墙需要开放3306
sudo ufw allow 3306