How To Fix “Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)” Error?


Please shareShare on Facebook135Share on Google+0Tweet about this on Twitter10Share on LinkedIn0Share on Reddit0Digg thisShare on StumbleUpon1Share on VKBuffer this page

I have successfully installed MySQL or MariaDB, after rebooting my system and running mysql -u root -p, I get the following error message:

[~]$ mysql -u root -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

Can't connect to local MySQL server through socket

 This definitely might be because you haven’t start MySQL server or MariaDB server.

Open Terminal and the command below to check the status:

# service mysql status

If the command above returns an error, you have definitely not started the server after booting.

Now start MariaDB:

# systemctl start mariadb.service


# systemctl start mysqld.service


Enable auto start at boot time:

# systemctl enable mariadb.service


# systemctl enable mysqld.service


If after all these and you still can’t access MariaDB, it means your installation wasn’t completed successfully:

Follow our article on How to Install LAMP Server (Apache, MariaDB And PHP) On Fedora 20/19