How To Fix “Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)” Error?
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)
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 OR # systemctl start mysqld.service
Enable auto start at boot time:
# systemctl enable mariadb.service OR # 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