Error "Can't connect to /tmp/mysql.sock"

Category: MySQL
Created: 2020-08-13

Problem: you get the error message Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ either within LiveConfig (Server management -> Databases) or in the LiveConfig log file.

Reason: the MySQL server creates a socket file e.g. at /var/run/mysqld/mysqld.sock, while the MySQL client expects this socket at /tmp/mysql.sock. This problem often occurs on systems with a broken default configuration (e.g. Ubuntu 16) or with manually installed MySQL/MariaDB packages.

Solution: the socket paths for the server and for the client need to be configured with the same value. The directory /var/run/mysqld/ is preferred over /tmp for security reasons. In the MySQL configuration (usually /etc/mysql/my.cnf) there’s both a configuration section for the server ([server]) and for the client ([client]). Search for the corresponding socket = ... setting and adjust it accordingly.

If your my.cnf file contains the command !includedir /etc/mysql/conf.d/ (usually at the end of the file), the cleanest solution is to create a file like /etc/mysql/conf.d/client.conf and add the following lines there:

[client]
socket = /var/run/mysqld/mysqld.sock

Then restart LiveConfig (to load the updated MySQL client configuration). MySQL doesn’t need to be restarted, except if you change the socket setting in the [server] section.