---
title: How to resolve – Can’t connect to local server through socket ‘/run/mysqld/mysqld.sock’ (2)
description: "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` ![](https://truehost.com/support/wp-content/uploads/2024/08/image-13.png) 1. In my case, the issue seems to be related to service unit file. So we…"
url: "https://truehost.com/support/knowledge-base/how-to-resolve-cant-connect-to-local-server-through-socket-run-mysqld-mysqld-sock-2/"
updated: "2024-08-28"
category: Servers
---

# 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`

![](https://truehost.com/support/wp-content/uploads/2024/08/image-13.png)

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.

![](https://truehost.com/support/wp-content/uploads/2024/08/image-14.png)

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

`systemctl unmask mariadb.service`

![](https://truehost.com/support/wp-content/uploads/2024/08/image-15.png)

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

`systemctl restart mariadb`

`systemctl status mariadb`

![](https://truehost.com/support/wp-content/uploads/2024/08/image-16-1024x242.png)

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.

![](https://truehost.com/support/wp-content/uploads/2024/08/image-17.png)

Done.
