Skip to Content

Can’t connect to local MySQL server through socket /tmp/mysql.sock

How to solve the error "Failed to connect to database: Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2). An error occurred. Please contact administrator"?


Overview: This article provides steps to resolve the "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)" error by updating the db_port variable in the "/usr/local/etc/ezlogin/ez.conf" file with the correct MySQL socket file path.


Step 1: Check the correct db_port variable. Login to MySQL and run the below command 

mysql> mysql -e "show variables like 'socket';"   
+---------------+-----------------------------+
| Variable_name | Value                       |
+---------------+-----------------------------+
| socket        | /var/run/mysqld/mysqld.sock |       
+---------------+-----------------------------+

Typically, the MySQL socket file is located at /var/lib/mysql/mysql.sock, but this can vary depending on the server. The command above will display the current path to the MySQL socket file in use. Otherwise, you may need to configure it manually in the MySQL configuration file, usually found at /etc/my.cnf.

Step 2: Update the Ezeelogin configuration file (ez.conf) with the correct db_port variable. Make sure that the MySQL socket does exist in the path specified in /usr/local/etc/ezlogin/ez.conf.

root@gateway:~# vi /usr/local/etc/ezlogin/ez.conf

db_port /var/run/mysqld/mysqld.sock       


Related Articles:

Can’t connect to local MySQL server through socket ’3306 ’ in ezsh.log

Basic MySQL commands for troubleshooting database-related issues in Ezeelogin