0

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
1
  • Could you please share what distribition you are using, what version of MySQL you are using, if it's MySQL or MariaDB; also, please run netstat -nlp |grep 3306, check the process ID (PID) of the binary listening on that port, and then the output if ps -AF |grep <PID here>. And please edit your question to add the new information, don't add it in the comments. Dec 3, 2018 at 6:57

1 Answer 1

0

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.

3
  • Also, your config file looks completely wrong. The only directive that starts with ! is !includedir. I would be surprised if the mysqld starts at all with this config file. Dec 2, 2018 at 11:38
  • I will remove !
    – Ian Arman
    Dec 2, 2018 at 21:53
  • Hello, Here are the two lines in /etc/mysql/my.cnf When I add bind-address = 0.0.0.0, and restart mysql using the following command sudo systemctl restart mysql the service will not start properly. However, If I add !bind-server 0.0.0.0 and restart the mysql server using the same command, the server starts properly, without any errors. !includedir /etc/mysql/conf.d/ !includedir /etc/mysql/mysql.conf.d/
    – Ian Arman
    Dec 3, 2018 at 4:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .