Mariadb error - Cannot connect to local server through socket

  • Last updated: Nov 3, 2023
  • Views: 1253
  • Author: Admin
Mariadb error - Cannot connect to local server through socket

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)".

mariadb_socket

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

mariadb_socket

mariadb_socket

 

Restarting the database.

$. service mariadb restart


 

Thank you all, I hope that my article helped you in some way.

SIMILAR ARTICLES

How to move the MariaDB data directory

How to move the MariaDB data directory

MariaDB - database backup - mysqldump

MariaDB - database backup - mysqldump

How to extend the MariaDB config file, includedir - include

How to extend the MariaDB config file, includedir - include