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

4

9
  • 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'.

Sherly answered 7/3, 2011 at 10:50 Comment(3)
You have a different networks eg: 172.16.0.* and 172.16.1.*. Can you ping from 172.16.0.114 to 172.16.1.169 at all?Testament
Same network....i can ping...Sherly
Same problem here. The [answer of guido][1] resolve my problem. Thx. [1]: https://mcmap.net/q/1179809/-problems-in-connecting-to-mysql-server-error-2003-hy000Ravin
M
9

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
Mcloughlin answered 1/8, 2011 at 11:17 Comment(0)
S
3

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

Save and restart mysql service.

Schapira answered 12/5, 2016 at 7:23 Comment(1)
This is solition of this question. I was same problem on ubuntu 14.04 server, mysql 5.6. I comment comment '#bind-address = 127.0.0.1' and it worked for meSchapira
A
2
  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

Agata answered 7/6, 2013 at 11:16 Comment(1)
Thank you, It worked! Can you explain what this lines change?Creepy
K
0

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

Once you get the correct port you can connect to that mysql server by using this command:

mysql -h 172.16.1.169 -P (port) -u root -p (password)
Kissel answered 30/7, 2013 at 14:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.