核心就是默认的3306端口没有对外开发,所以首先查看一下:
netstat -an|grep 3306
开始显示的是127.0.0.1:3306
执行:
vi /etc/mysql/mysql.conf.d/mysqld.cnf
其中一行 bind-address = 127.0.0.1
前边加 #注释掉 保存(可能会遇到提示 readonly 请自行修改权限)
执行:
sudo mysql -u root -p
输入 mysql密码
mysql> grant all privileges on . to ‘root’@’%’ identified by ‘上边的密码’;
mysql>flush privileges;
重启下 sudo reboot now