##远程连接mysql数据库失败:Can’t connect to MySQL server on ‘root'(10038)的解决办法
下面是一些解决方案 在我使用的最新LNMP环境包的时候遇到的情况是防火墙iptables 阻止了外网IP访问3306
我的解决方案是清除iptables规则 解放3306
清除已有iptables规则
iptables -F
iptables -X
(我本人执行到这一步就可以了)
1、设置用户权限
修改用户远程登录权限:
比如想给用户root(密码:123456)设置从任何主机连接到mysql服务器:
连接linux,登录数据库:# mysql -uroot -p
# Enter password:******
MySQL [(none)]> use use mysql;
MySQL [(mysql)]> GRANT ALL PRIVILEGES ON *.* TO ’root‘@'%' IDENTIFIED BY ‘123456’ WITH GRANT OPTION;
MySQL [(mysql)]> flush privileges;
MySQL [(mysql)]> quit;
报这个错误的话 ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'identified by "123456"' at line 1
用下面这句
create user root@'%' identified by '123456';
grant all privileges on *.* to root@'%' with grant option;
重启MySQL:# service mysqld restart
2、检查防火墙有没有屏蔽掉3306端口。
Centos系统的话,编辑 /etc/sysconfig/iptables:# vim /etc/sysconfig/iptables
加入一行:-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
重启iptables:# service iptables restart