Bootstrap FreeKB - mySQL / MariaDB - Resolve "ERROR 2003 (HY000) Cant connect to MySQL server (111)" (connection refused)
mySQL / MariaDB - Resolve "ERROR 2003 (HY000) Cant connect to MySQL server (111)" (connection refused)

Updated:   |  mySQL / MariaDB articles

Let's say the following is displayed when attempting to connect to mySQL or MariaDB.

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


The most relevant part of this error message is (111), the error code.

The perror command line tool can be used to determine what the error code represents.

~]# perror 111
OS error code 111:  Connection refused


localhost vs. % (remote) connections

Users are allowed to connection to mySQL or MariaDB via locahost or remote.

  • localhost means that the user is making the connection on the system that contains the mySQL or MariaDB service (in other words, the actual mySQL or MariaDB server).
  • % (remote) means that the user is making the connection from some other system.

If you have access to the system running mySQL or MariaDB, and you have been granted the select permission, you can determine if a user is allowed to make a localhost connection, a remote connection, or both.

~]# mysql --execute="select Host,User from mysql.user \G"
*************************** 1. row ***************************
Host: localhost
User: root
*************************** 2. row ***************************
Host: %
User: root
*************************** 3. row ***************************
Host: %
User: john.doe


remote connections and bind address

For remote connections, you will also need to bind mySQL or MariaDB to the IP address of the system.



Refer to these articles:


General Log and Error Log

The general log and error log may have events that correlate to the failed connection. This command can be used to determine if the logs are enabled and the location of each log.

~]# mysql --execute="show variables" | egrep -ie 'general_log|log_error'
general_log       OFF
general_log_file  /var/log/mysql_general.log
log_error         /var/log/mysqld.log


The /etc/my.cnf or /etc/my.cnf.d/mariadb-server.cnf file should contain the log-error directive. In this example, MariaDB is configured to log errors to the /var/log/mariadb/mariadb.log file. Check the error log to see if there are any events that correlate to the failed connection.



Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee


Add a Comment

Please enter 0b4741 in the box below so that we can be sure you are a human.