Problems connecting to mysql server: ERROR 2003 (HY000)

  • Server ip: 172.16.1.169
  • mysql username: root
  • passwd: xxxxxxxxxx
  • database name: example

I am trying to access the database from the client (ip 172.16.0.114). The Fedora Linux distribution is running on the server and client. What parameters need to be configured and why should they be configured, both for the server and for the client? How to access a specific database (here, "example")? I tried, but I had an error:

ERROR 2003 (HY000): Cannot connect to MySQL server on "172.16.1.169".

+6
linux mysql mysql-error-2003 fedora
source share
4 answers

This error message is generated by the client (not the server) because a connection to the server was made, but the server could not be reached.

There are various possible reasons:

1) check that mysqld is running on the server:

ps -ef | grep mysqld 

should return something like:

 root 2435 2342 0 15:49 pts/1 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/var/ --user=mysql mysql 2480 2435 0 15:49 pts/1 00:00:00 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/var/ --user=mysql ... 

To start the daemon service, start redhat / fedora / centos:

 service mysqld start 

or in the Fedora release> = 16, which depends on systemd:

 systemctl start mysqld.service 

and to enable the daemon to start automatically when the system boots:

 systemctl enable mysqld.service 

2) check the port on which mysqld is running on the server:

 netstat -lnp | grep mysql 

should return:

 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2480/mysqld unix 2 [ ACC ] STREAM LISTENING 8101 2480/mysqld /tmp/mysql.sock 

the latter is a socket for local connections, the former is the TCP port for the network (3306 by default). If the port is not the default port, you must set the connection port on the client. When using mysql client:

 mysql dbname -uuser -ppasswd -P<port> ... 

3) located on a different network address, check that the server is listening on the network add to which you are connecting: in the /etc/my.cnf file /etc/my.cnf find the line:

 bind_address=127.0.0.1 

if the address 127.0.0.1 only local connections are allowed; if it was 172.16.1.0, you could not connect to 172.16.2.xxx

4) check that the server does not have a firewall and block connections to the mysql port (3306 is the default port); if it runs redhat / fedora / centos

 service iptables status 
+8
source share
  • Open the MySQL configuration file

    sudo vim my.cnf

  • Make sure the following comments are commented out.

    # pass external lock

    # skip networks

    # bind-address = xx.xx.xx.xx

    Save and exit

  • Restart mysql service

+1
source share

I think mysql destination server might use a different port. You must first find the correct port.

Once you get the correct port, you can connect to this mysql server using the following command:

 mysql -h 172.16.1.169 -P (port) -u root -p (password) 
0
source share

In the MySQL configuration file (/etc/mysql/my.cnf), the comment is '# bind-address = 127.0.0.1'

Save and restart the mysql service.

-one
source share

All Articles