ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.157' (111)

来源:互联网 发布:php程序员培训机构 编辑:程序博客网 时间:2024/06/06 04:35

1.MySQL本地可以登录,但是不能远程登录。

[root@nb0 ~]# mysql -h192.168.1.157 -uroot -pEnter password: ERROR 2003 (HY000): Can't connect to MySQL server on '192.168.1.157' (111)

2. MySQL服务器是可以ping通的

[root@nb0 ~]# ping 192.168.1.157PING 192.168.1.157 (192.168.1.157) 56(84) bytes of data.64 bytes from 192.168.1.157: icmp_seq=1 ttl=64 time=0.242 ms64 bytes from 192.168.1.157: icmp_seq=2 ttl=64 time=0.262 ms^C--- 192.168.1.157 ping statistics ---2 packets transmitted, 2 received, 0% packet loss, time 1000msrtt min/avg/max/mdev = 0.242/0.252/0.262/0.010 ms

3. MySQL的端口是默认的

[root@my ~]# netstat -nlp|grep 3306tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      24061/mysqld    

4.解决办法

将mysql配置文件中的bind-address = 127.0.0.1注释掉

[root@my ~]# vi /etc/mysql/mysql.conf.d/mysqld.cnf ## Instead of skip-networking the default is now to listen only on# localhost which is more compatible and is not less secure.#bind-address           = 127.0.0.1

如果安装的是Mariadb10,对应目录文件会发生一些改变

[root@my ~]# cd /etc/mysql/mariadb.conf.d[root@my ~]/etc/mysql/mariadb.conf.d# ls50-client.cnf  50-mysql-clients.cnf  50-mysqld_safe.cnf  50-server.cnf

然后编辑50-server.cnf文件,同样是注释掉bind-address

vi 50-server.cnf

重启MySQL

[root@my ~]:~# sudo service mysql restart

重新远程连接

[root@nb0 ~]# mysql -h192.168.1.157 -uroot -pEnter password: Welcome to the MariaDB monitor.  Commands end with ; or \g.Your MySQL connection id is 10Server version: 5.7.11-0kord6 (Ubuntu)Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MySQL [(none)]>
1 0
原创粉丝点击