ERROR 2003 (HY000): Can’t connect to MySQL server on ‘192.168.100.10’ (113)

1.尝试远程连接数据库(192.168.100.11服务器)
[root@node2 mysql]# mysql -h 192.168.100.10 -P 3306 -u www -p
Enter password: 
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.100.10' (113)
提示错误,不能连接远程数据库。
2.测试是否能ping到远程机器(192.168.100.11服务器)
[root@node2 mysql]# ping 192.168.100.10
PING 192.168.100.10 (192.168.100.10) 56(84) bytes of data.
64 bytes from 192.168.100.10: icmp_seq=1 ttl=64 time=0.299 ms
64 bytes from 192.168.100.10: icmp_seq=2 ttl=64 time=0.229 ms
64 bytes from 192.168.100.10: icmp_seq=3 ttl=64 time=0.230 ms
64 bytes from 192.168.100.10: icmp_seq=4 ttl=64 time=0.251 ms
64 bytes from 192.168.100.10: icmp_seq=5 ttl=64 time=0.322 ms
64 bytes from 192.168.100.10: icmp_seq=6 ttl=64 time=0.293 ms
能ping通,说明网络是连通的。
3.登录到数据库端(192.168.100.10服务器),添加一个Host为“%”的用户
[root@node1 ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.22-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select Host,User from mysql.user;
+-----------+---------------+
| Host      | User          |
+-----------+---------------+
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
3 rows in set (0,00 sec)

mysql> grant all privileges on *.* to 'www'@'%' identified by '123456';
Query OK, 0 rows affected, 1 warning (0,01 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0,00 sec)

mysql> select Host,User from mysql.user;
+-----------+---------------+
| Host      | User          |
+-----------+---------------+
| %         | www           |
| localhost | mysql.session |
| localhost | mysql.sys     |
| localhost | root          |
+-----------+---------------+
4 rows in set (0,00 sec)
4.再次远程访问(192.168.100.10服务器)
[root@node2 mysql]# mysql -h 192.168.100.10 -P 3306 -u www -p
Enter password: 
ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.100.10' (113)
还是提示错误,不能连接远程数据库。
5.可能不能访问端口号,测试端口号是否能访问。(192.168.100.12服务器)
[root@node2 mysql]# telnet 192.168.100.10 3306
Trying 192.168.100.10...
telnet: connect to address 192.168.100.10: No route to host
找到问题所在了,防火墙屏蔽了这个端口号。
6.直接关闭防火墙即可(192.168.100.10服务器)
[root@node1 ~]# systemctl disable firewalld
rm '/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service'
rm '/etc/systemd/system/basic.target.wants/firewalld.service'

[root@node1 ~]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service
7.测试端口号是否能访问(192.168.100.12服务器)
[root@node2 mysql]# telnet 192.168.100.10 3306
Trying 192.168.100.10...
telnet: connect to address 192.168.100.10: No route to host
[root@node2 mysql]# telnet 192.168.100.10 3306
Trying 192.168.100.10...
Connected to 192.168.100.10.
成功访问
8.再次远程访问(192.168.100.12服务器)
[root@node2 mysql]# mysql -h 192.168.100.10 -P3306 -uwww -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.22-log MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
连接成功!

您可以选择一种方式赞助本站

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: