1、首先对用户开启远程连接的权限,开放3006端口,开启其他的ip也能访问%
grant all privileges on *.* to 'root'@'%' identified by 'youpassword' with grant option;
flush privileges; //刷新MySQL的系统权限相关表
quit; // 退出mysql
youpassword是自己的数据库密码
service mysql restart #重启mysql命令
2、如果还访问不了需要记得关闭防火墙,具体步骤如下
但是centos7的防火墙默认使用的是firewall作为防火墙,这里改为iptables防火墙步骤。
1、关闭firewall:
-
systemctl stop firewalld.service #停止firewall
-
systemctl disable firewalld.service #禁止firewall开机启动
-
firewall-cmd --state #查看默认防火墙状态(关闭后显示notrunning,开启后显示running)
-
到此步骤我的数据库就连接成功啦