How to resolve – Can’t connect to local server through socket ‘/run/mysqld/mysqld.sock’ (2)

For some reason you try to access your database and get the error Can’t connect to local server through socket ‘/run/mysqld/mysqld.sock’ (2) mysql systemctl daemon-reload 2. Then enable the service systemctl enable mariadb.service However I got the error below. Failed to enable unit: Unit file /etc/

Last updated 30 Nov 2026

For some reason you try to access your database and get the error Can’t connect to local server through socket ‘/run/mysqld/mysqld.sock’ (2)

mysql

  1. In my case, the issue seems to be related to service unit file. So we reload this configuration.

systemctl daemon-reload

2. Then enable the service

systemctl enable mariadb.service

However I got the error below.

Failed to enable unit: Unit file /etc/systemd/system/mariadb.service is masked.

3. Run the command below to address the issue and enable the service.

systemctl unmask mariadb.service

4. Then we try to restart the service, which also fails due to an error below.

systemctl restart mariadb

systemctl status mariadb

5. From the error it seems there are some packages missing needed to start the service, so we install the packages.

Confirm you have the database is installed.

mariadb --version or mysql --version

Then,

sudo apt -y update

Then,

sudo apt install mariadb-client mariadb-server

Start the database server and confirm the status. All should be good.

Done.