ERROR 2003 (HY000)

问题:

[root@master2 ~]# mysql -uolding -pmysql -h 10.0.0.51 -P 3306
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Can't connect to MySQL server on '10.0.0.51' (113)

分析:

1、测试是否能ping到远程机器

[root@master2 ~]# ping 10.0.0.51
PING 10.0.0.51 (10.0.0.51) 56(84) bytes of data.
64 bytes from 10.0.0.51: icmp_seq=1 ttl=64 time=0.661 ms
64 bytes from 10.0.0.51: icmp_seq=2 ttl=64 time=0.475 ms
64 bytes from 10.0.0.51: icmp_seq=3 ttl=64 time=0.550 ms
64 bytes from 10.0.0.51: icmp_seq=4 ttl=64 time=0.642 ms
64 bytes from 10.0.0.51: icmp_seq=5 ttl=64 time=0.676 ms
64 bytes from 10.0.0.51: icmp_seq=6 ttl=64 time=0.628 ms
64 bytes from 10.0.0.51: icmp_seq=7 ttl=64 time=0.597 ms
64 bytes from 10.0.0.51: icmp_seq=8 ttl=64 time=0.618 ms
64 bytes from 10.0.0.51: icmp_seq=9 ttl=64 time=0.558 ms
64 bytes from 10.0.0.51: icmp_seq=10 ttl=64 time=1.38 ms
^V64 bytes from 10.0.0.51: icmp_seq=11 ttl=64 time=0.619 ms
^C
--- 10.0.0.51 ping statistics ---
11 packets transmitted, 11 received, 0% packet loss, time 10010ms
rtt min/avg/max/mdev = 0.475/0.673/1.389/0.235 ms

说明网络是连通的,再测试以下端口号

 

2、登录到数据库端

[root@master1 ~]# mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.7.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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 user,host from mysql.user;
+---------------+-----------+
| user          | host      |
+---------------+-----------+
| olding        | 10.0.0.%  |
| root          | 10.0.0.%  |
| mysql.session | localhost |
| mysql.sys     | localhost |
| olding        | localhost |
| root          | localhost |
+---------------+-----------+
6 rows in set (0.01 sec)

添加

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

mysql> flush privileges;  # 手工加载授权表
Query OK, 0 rows affected (0.00 sec)

再次远程访问

[root@master2 ~]# mysql -uapp -pmysql -h 10.0.051
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 2003 (HY000): Can't connect to MySQL server on '10.0.051' (113)

 

2、还是无法连接到数据库,可能不能访问端口号,再次测试

[root@master2 ~]# yum install telnet -y
[root@master2 ~]# telnet 10.0.0.51 3306
Trying 10.0.0.51...
telnet: connect to address 10.0.0.51: No route to host

找到问题所在了,防火墙屏蔽了这个端口号。

 

3、直接关闭防火墙即可。

[root@master2 ~]# systemctl disable firewalld
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@master2 ~]# service firewalld stop
Redirecting to /bin/systemctl stop firewalld.service
[root@master2 ~]# telnet 10.0.0.51 3306
Trying 10.0.0.51...
Connected to 10.0.0.51.
Escape character is '^]'.
J
5.7.28
      c0F6 
<\R4pe@;x#[mysql_native_password
mysql
!#08S01Got packets out of orderConnection closed by foreign host.

再次远程访问

[root@master2 ~]# mysql -uapp -pmysql -h 10.0.0.51 -P 3306
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 12
Server version: 5.7.28 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, 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> 

成功了。

 

posted @ 2020-07-30 13:07  丁海龙  阅读(398)  评论(0)    收藏  举报