无法连接远程MySQL服务器(CentOS),我已经尝试了很多方法,但没有帮助。
我可以成功地ssh远程主机,端口3306正在侦听:
[root@fabulous ~]# netstat -lntp Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 9979/mysqld
我已经closures了iptables:
[root@fabulous ~]# service iptables stop iptables: Setting chains to policy ACCEPT: filter [ OK ] iptables: Flushing firewall rules: [ OK ] iptables: Unloading modules: [ OK ]
远程服务器上的Mysql客户端正常工作,并允许在每个主机上访问:
mysql> select user,host from user; +-------+--------------------+ | user | host | +-------+--------------------+ | root | % | | root | 127.0.0.1 | | root | fabulous.ma2oo.com | | root | localhost | +-------+--------------------+ 4 rows in set (0.00 sec)
mysql的全局configuration:
[root@fabulous ~]# vi /etc/my.cnf [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid [mysql] default-character-set=utf8
但是,当我在Windows笔记本电脑上使用Navicat访问mysql服务器时,错误消息是:
2003 - Can't connect to MySql server on 'XX.XX.XX.XX' (10038)
当我使用telnet访问该服务器上的相应端口时,错误消息是:
C:\Users\shijunji>telnet 107.170.239.240 3306 Connecting To 107.170.239.240...Could not open connection to the host, on port 3306: Connect failed
任何人都可以知道它或让我知道如何find有用的日志? 提前致谢。
我认为你的Navicat或你的Windows操作系统并不好。
在我的本地主机上,
songguo@songuo:~$ telnet 107.170.239.240 3306 Trying 107.170.239.240... Connected to 107.170.239.240. Escape character is '^]'. 4 5.1.73 ^^=Vxyw1P"Ue}ffL+.G Connection closed by foreign host. songguo@songuo:~$ mysql -uroot -h107.170.239.240 -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'211.151.238.51' (using password: YES)
所以,如果我有正确的密码,我可以连接到MySQL服务器。
看起来好像端口3306正在被你和CentOS服务器之间的防火墙或其他网络设备阻塞。
我建议您通过SSH连接连接到MySQL服务器,以便以localhost用户的身份连接到服务器。 使用SSH应该允许你从你的办公室连接,同时也提供加密的连接和保护,免受潜在的中间人攻击。 我从来没有使用过Navicat,但连接设置MySQL Workbench可以很容易地使用SSH进行连接。
为了安全起见,您还应该在您的服务器上重新启用iptables ,并阻止外部网络访问端口3306,以便只有localhost用户(包括使用SSH隧道的用户)才能连接。
另外,您还可以启用SSL来安全地连接到服务器,但创建,签署和分发私钥和公共证书到服务器和所有客户端的后勤工作使其难以实现。 此外,通过SSL连接使用相同的TCP端口(3306),这不利于阻止该端口的流量的情况。
检查你的/etc/mysql/my.cnf文件,并在bind-address = 127.0.0.1之前加一个#