Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problems in connecting to mysql server: ERROR 2003 (HY000)

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

I'm trying to access a database from a client (ip 172.16.0.114). Both the server and client are running the Fedora distribution of Linux. What settings need to be configured, and what should they be set to, for both the server and client? How do I access a specific database (here, "example")? I tried but I got an error:

ERROR 2003 (HY000): Can't connect to MySQL server on '172.16.1.169'.

like image 401
Jagan Avatar asked Mar 07 '11 10:03

Jagan


3 Answers

That error message is generated by the client (not the server) because a connection to the server has been attempted but the server could not be reached.

There are various possible causes to that:

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 run the daemon service, run on redhat/fedora/centos:

service mysqld start

or on Fedora release >= 16, which relies on systemd:

systemctl start mysqld.service

and for enabling daemon auto-startup at system boot:

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 the socket for local connections, the first the tcp port for networking (default 3306). If the port is not the default port, you must set the connection port on the client. If using mysql client:

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

3) being on a different net address, check that the server listens for the net addrees your are connecting from: in file /etc/my.cnf search for the line:

bind_address=127.0.0.1

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

4) check that on the server there is no firewall running and blocking connections to mysql port (3306 is the default port); if it's a redhat/fedora/centos run

service iptables status
like image 115
guido Avatar answered Oct 14 '22 14:10

guido


  1. Open MySQL config file

    sudo vim my.cnf

  2. Ensure that the following are commented out.

    #skip-external-locking

    #skip-networking

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

    Save and exit

  3. Restart mysql service

like image 39
Pankaj Khurana Avatar answered Oct 14 '22 12:10

Pankaj Khurana


In MySQL config file (/etc/mysql/my.cnf) comment '#bind-address = 127.0.0.1'

Save and restart mysql service.

like image 1
Ramil Mammadov Avatar answered Oct 14 '22 12:10

Ramil Mammadov