Skip to Content

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

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


synopsis: 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.


step1. Check the correct db_port variable using the below command 

root@Remote:~# mysql -e "show variables like 'socket';"   
+---------------+-----------------------------+
| Variable_name | Value                       |
+---------------+-----------------------------+
| socket | /var/run/mysqld/mysqld.sock        |
+---------------+-----------------------------+

Usually it would be /var/lib/mysql/mysql.sock but varies from server to server.

step 2. Edit the ez.conf file with the db_port variable.

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

              db_port /var/run/mysqld/mysqld.sock       

The command above would show the path to the mysql socket file that is current in use, else you would need to setup them in the mysql configuration file usually found in /etc/my.cnf.
You would need to make sure that the mysql sock does exist in the path specified in /usr/local/etc/ezlogin/ez.conf.


Related Article

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

Basic MySQL commands for troubleshooting database related issues in Ezeelogin