Mariadb error - Cannot connect to local server through socket
Last updated: Jun 29, 2022
Colleagues hello to all.
In today's article, we'll talk about the issue when connecting to the Mariadb database after moving the database files to another location.
The problem is called - "ERROR 2002 (HY000): Can't connect to local server through socket '/var/lib/mysql/mysql.sock' (2)".
This problem occurs when you move the database to another directory and specify the new directory in the configuration file via the datadir variable, but forget to specify another variable.
To solve this problem, you need to add the path to the "socket" socket file in the configuration file. You need to write the path to the socket not only in the server.cnf file, but also in client.cnf.
In my case, my database files are stored in the "/app/mysql/data" so I will add the socket file to this directory.
conf> socket = /app/mysql/data/socket.sock
Restarting the database.
$. service mariadb restart
Thank you all, I hope that my article helped you in some way.