系统配置
Ubuntu 18.04
服务器搭在华为云上
MySQL版本 5.7.32
解决方案
- 确保云服务主机开启端口,需要修改安全组;
- 主机防火墙开启了端口;
- Mysql没有bind-address;
/etc/mysql/mysql.conf.d/mysqld.cnf 中把bind-address = 127.0.0.1
备注掉。 - MySQL设置权限
grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option; FLUSH PRIVILEGES;
- mysql -uroot -h x.x.x.x -p123456 就可以连上了
小结
主要是学习性质,这种开放端口的方式并不安全。