Fix MySQL/MariaDB socket error

Socket file helps to facilitate communication between different processes of the MySQL and MariaDB server. The file associated with the process is, mysqld.sock and is located at the folder, /var/run/mysqld/. Due to many reasons, MariaDB cannot establish a connection with the socket file. Sometimes socket files are missing from the location. It results in the stopping of the MariaDB service. The problem with the socket file also affects the working of Koha. Often Koha screen shows the following error on the screen.

Possible solutions

We can try to apply three solutions to evoke socket files; restarting the MariaDB service, changing user permissions, and reinstalling MariaDB. 

Solution 1: Try to restart the MariaDB service and check whether it's working.

sudo systemctl start mariadb

Refresh the Koha page. If it works, it means the socket file works. If it does not open, we go to the next solution.

Solution 2: Next, we will check whether the mysqld. sock file missing or not. Apply the following command,

ls -a /var/run/mysqld

The file is there, we can see a file with the name, mysqld.sock. If the file is missing from there, the reason may be that MariaDB has no proper permissions to create it. Give the directory permission to MariaDB users to make necessary changes.

sudo chown mysql:mysql /var/run/mysqld/
sudo chmod -R 755 /var/run/mysqld/

Restart the MariaDB service,

sudo systemctl restart mysql

If it is reluctant to start the service and shows the error, find other ways to solve it. The last resort is to reinstall the MariaDB.

Solution 3: Reinstall MariaDB

The first step is the uninstall the MariaDB without removing the Koha databases  (e.g. koha_library). The default location of the data directory of MariaDB is at /var/lib/mysql/, where we can see the Koha database directory.

The location of MariaDB data directory, /var/lib/mysql/
Apply the following commands to uninstall MariaDB,

sudo apt purge "mariadb*" -y

When it asks for deleting databases, give the answer No. It will retain the Koha database.

Apply the following command to remove unwanted packages after the uninstallation of MariaDB.
sudo apt autoremove -y

Apply the following command to reinstall the MariaDB,

sudo apt-get install mariadb-server mariadb-client

I faced the socket problem with MariaDB 10.3 on Ubuntu 20.04. I used the opportunity and installed a higher version of MariaDB (10.04) by adding a repository. The download page in the MariaDB home page gives you instructions to install a higher version of the package. Please check it, https://mariadb.org/download/?t=repo-config

After the successful installation of MariaDB, open the Koha Staff Client and check the page loads or not.

References

How To Troubleshoot Socket Errors in MySQL https://www.digitalocean.com/community/tutorials/how-to-troubleshoot-socket-errors-in-mysql

MariaDB installation - dependency problems and failed to start service https://mariadb.com/kb/en/mariadb-installation-dependancy-problems-and-failed-to-start-service/

No comments:

Post a Comment