Mysql – ERROR 2003 (HY000): Can’t connect to MySQL server on ‘XXX.XXX.XXX.XXX’ (111)

MySQL

I'm running the following mysql command:

mysql -h 10.8.0.16  -u username -p

after typing the password, I receive the following error:

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

Here's the contents of /etc/mysql/mysql.cnf

!bind-address = 0.0.0.0
!server-id               = 1
#!relay-log               = /var/log/mysql/mysql-relay-bin.log
!log_bin                 = /var/log/mysql/mysql-bin.log
#!binlog_do_db            = newdatabase
!ibinlog-ignore-db = "database"
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/

Here is the result of my netstat

$ netstat -an | grep tcp | grep 3306
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:57630         127.0.0.1:3306          ESTABLISHED
tcp        0      0 127.0.0.1:3306          127.0.0.1:57630         ESTABLISHED
tcp        1      0 127.0.0.1:57628         127.0.0.1:3306          CLOSE_WAIT
tcp        1      0 127.0.0.1:57570         127.0.0.1:3306          CLOSE_WAIT
tcp        1      0 127.0.0.1:57600         127.0.0.1:3306          CLOSE_WAIT
tcp        1      0 127.0.0.1:57594         127.0.0.1:3306          CLOSE_WAIT
tcp        1      0 127.0.0.1:57608         127.0.0.1:3306          CLOSE_WAIT

Best Answer

Your MySQL is configured to bind only to 127.0.0.1. Configure bind-address properly:

/etc/mysql/my.cnf:

bind-address = 0.0.0.0

Don't forget to restart mysqld afterwards.