前提:服务器ubuntu
1.开启3306端口
查看是否开启3306端口
firewall-cmd --list-ports
如果没有3306,添加端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
重启防火墙
firewall-cmd --reload
2.打开mysql配置文件,将bind-address=127.0.0.1注释
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
3.重启ubuntu
sudo reboot
4.开启远程连接
免密登录mysql
mysql -u -root
使用数据库
use xxx;
添加用户权限
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
flush privileges;
表示所有主机都可以root为密码登录远端服务器的root用户