ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2) with MariaDB & MySQL


I’m using the latest, fully upgraded EndeavourOS. I have installed MySQL and replaced it with MariaDB and have failed to get either to work. I consistently get the error of:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)

Here is the output when I run mysqld --verbose:

2020-07-31 17:29:52 0 [Note] mysqld (mysqld 10.4.13-MariaDB) starting as process 11330 ...
2020-07-31 17:29:52 0 [Warning] Can't create test file /var/lib/mysql/username.lower-test
mysqld: Can't change dir to '/var/lib/mysql/' (Errcode: 13 "Permission denied")
2020-07-31 17:29:52 0 [ERROR] Aborting

Running sudo systemctl start mariadb.service, I got the following error log: (put in a pastebin because its otherwise quite long)

I have tried various solutions from online, including from these following links:

I had this issue when I had installed MySQL as well. Let me know if there are any other things I should post here.

Hello @MagusZ

Don’t know much about MariaDB but it looks like the service needs to be started.

sudo systemctl start mariadb.service

sudo systemctl enable mariadb.service

Edit: Probably the same issue with MySQL

I tried this and got this error:

Failed to start maraidb.service: Unit maraidb.service not found.

I then tried reinstalling mariadb and the issue wasn’t fixed.

Check spelling! marai != maria …

1 Like
[ERROR] InnoDB: Plugin initialization aborted with error Data structure corruption

Remove the MySQL database files from /var/lib/mysql and reinitialise using mariadb-install-db (

1 Like

Ya sorry i misspelled it. My bad! :roll_eyes:

This happens to me sometimes when a mariadb update occurs.
In my case the issue is usually within the service file itself. Check the user running the service:

$ cat /usr/lib/systemd/system/mariadb.service

Then check if that user has read/write rights to the folder/file mentioned in the error.
Also if your database files are located somewhere other than the default, check that the datadir=[database_files_path] is correctly set up in /etc/my.conf
Sometimes the file gets overwritten on updates.
If it’s set to a folder in your /home /run/user /usr /boot or /etc directory make sure to allow this by setting the ProtectHome or ProtectSystem parameters to false in the service file (/usr/lib/systemd/system/mariadb.service):

Two points:

  1. If it gets overwritten then there’s an issue with the upgrade; old config files should at least be saved as a .pacsave.
  2. Putting customisation under /etc/my.cnf.d/ will avoid editing package-installed files. :wink:

Well then, in my case it’s probably a consequence of using a symlink to a file in my home directory instead of an actual /etc/my.conf file. I like to have all my config files in one place under my home folder, so I can reuse everything on re-installs. Same with the database files.
However the mariadb.service file I can confirm it sometimes gets overwritten by updates (that one I haven’t symlinked).

1 Like

That sounds reasonable - service files aren’t “meant” to be edited, so won’t be in the PKGBUILD’s backup array (also linked below).

systemctl edit mariadb is a good way to override elements of a unit’s behaviour which won’t be removed when the service file is upgraded.

That’s what I was telling myself until I noticed that there are a few settings in the service file that IMO belong into the my.cnf file. Like the two parameters I mentioned in the previous post.

Interesting. Never heard of systemctl edit before. I never stop learning.


Hi, thanks so much for all the help!

@nate I had already done what you had suggested beforehand with the ProtectHome etc. It still gave the same error running mysqld --verbose.

@jonathon I had a pacsave. I reconverted the file to a regular file, this likely was a bad idea. Forgive my newness to this. I also did try moving things around as specified in the links I had put. I will try systemctl edit mariadb and see how it goes. I haven’t tried removing the mysql files yet because I’m not sure what to remove (I’m completely new to MariaDB and am installing it to learn how to use it), should I remove everything in the directory?


I removed everything and tried it and am getting the same error, as you can see here:

That’s a different error.


indicates a permissions issue.

Possibly you’re trying to run the initialisation steps as your normal user rather than e.g. root (or using sudo).


tells you where to look for more information.

Have you read the MariaDB installation steps on the Arch wiki page?

First off, apologies for me being as dumb with this as I am. I did what you said, followed the Arch Wiki guide, and was now finally able to start the service. I then ran sudo chmod 755 for the folder and it seemingly went through but did not fix the issue.

What issue are you trying to solve by doing that?