Quantcast
Viewing all articles
Browse latest Browse all 26

Ubuntu MySQL Client Remote Connection ERROR 2003 (HY000): Can’t connect to MySQL server

Fresh installed database MySQL Server version 5.7.23 on Ubuntu 16.04 named “pc1” for hosting web application data.

Test remote connection from another computer “pc2” via MySQL Client:

root@pc2:~# mysql -u techxplore -h pc1 -p
Enter password:

ERROR 2003 (HY000): Can’t connect to MySQL server on ‘pc1’ (111)

root@pc2:~#

It throws an error – ERROR 2003 (HY000): Can’t connect to MySQL server.

On the other hand, test from local computer “pc1” via MySQL Client:

root@pc1:~# mysql -u techxplore -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.23-0ubuntu0.16.04.1 (Ubuntu)

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>

It works fine without any error.

Remote client can not connect. Remote connection is denied, even when the firewall on “pc1” is configured to allow connection from IP address of remote pc “pc2”. The same error even if MySQL server port 3306 is opened.

The MySQL server seem to be only listening to localhost which means remote connection are not allowed by default.

The solution was to change the MySQL Server configuration file to bind-address to the MySQL server IP address instead of the localhost default 127.0.0.2.

root@pc1:~# vi /etc/mysql/mysql.conf.d/mysqld.cnf

go to line 43 then change localhost ip (127.0.0.1)
bind-address = 127.0.0.1
to server ip (192.168.10.10):
bind-address = 192.168.10.10
save the configuration file then restart MySQL server

root@pc1:~# systemctl restart mysql

Try again connection from remote computer:

root@pc2:~# mysql -u techxplore -h pc1 -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.23-0ubuntu0.16.04.1 (Ubuntu)

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>

Now everything works fine without any error.


Viewing all articles
Browse latest Browse all 26

Trending Articles