Wondering how to resolve ‘Can’t connect to mysql error 111’? We can help you.
When we try to access mysql server on Linux machine using the public IP address, it is showing error 111.
Here at Bobcares, we get requests from our customers to fix similar issues as a part of our Server Management Services.
Today, let’s see how our Support Engineers fix this issue for our customers.
Cause for ‘Can’t connect to mysql error 111’ error
Usually, this error occurs when mysqld only listens to the localhost interface.
When we try to access mysql server on Linux machine using the public IP address, it often shows error 111. However, when localhost and 127.0.0.1 is used, it is connecting fine.
# ifconfig | grep “inet addr” inet addr:127.0.0.1 Mask:255.0.0.0 inet addr:126.96.36.199 Bcast:188.8.131.52 Mask:255.255.255.0
# mysql -ubob -pbob -hlocalhost Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 160 Server version: 5.1.31-1ubuntu2 (Ubuntu) # mysql -ubob -pbob -h127.0.0.1 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 161 Server version: 5.1.31-1ubuntu2 (Ubuntu)
The error message appears as below:
# mysql -ubob -pbob -h184.108.40.206 ERROR 2003 (HY000): Can’t connect to MySQL server on ‘220.127.116.11’ (111)
Solution for ‘Can’t connect to mysql error 111’ error
Let us see how our Support Techs resolved the error.
Before we proceed with the steps to fix the issue, check the MySQL status. You can check MySQL status following below provided steps:
1.Initially, check if the MySQL is running without any issue.
sudo ps wwaux | grep -i sql
2. If that does not output anything, try starting the MySQL service:
sudo service mysql start
3. Also, check hostname/port is MySQL listening on
sudo netstat -plutn | grep -i sql
If the MySQL is running without any issue, please go ahead with the below mentioned steps:
1. Firstly, in my.cnf configuration file, we should comment the following line in the mysqld section.
bind-address = 127.0.0.1
We can comment by adding # at the beginning of a line.
Once this is done, restart mysql.
$ sudo service mysql restart
To do this, we must have root or sudo access to the server.
2. Then, we should check the user privileges.
Login as root to mysql and add this:
CREATE USER ‘root’@’18.104.22.168’ IDENTIFIED BY ‘***’; GRANT ALL PRIVILEGES ON *.* TO ‘root’@’22.214.171.124’ IDENTIFIED BY ‘***’ WITH GRANT OPTION MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0;
Finally, you can try to connect again using mysql -ubob -pbob -h126.96.36.199. to check its working.
[Need assistance? We can help you]
In short, we saw how our Support Engineers fix this mysql error on Linux machine for our customers.