'I faced error message Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' when I tried to connect local mysql server

I am trying to connect my local MySQL server, but I am facing this error message.

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'

I tried many solutions on different websites, but none of them did not work. As an instance, I tried to kill the mysql and mysqld processes and then restart the MySQL service, but not worked. Or I executed these lines (from another site):

sudo chmod -R u+rwx /etc/mysql/
sudo chown -R mysql.mysql /etc/mysql/

but did not work and gave me the new error message:

Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.

Could you please help me with this problem? Thanks



Solution 1:[1]

Finally, after about 3 hours of searching on net, the solution founded on this site :-) https://askubuntu.com/questions/1008298/cant-start-mysql-server-database-corruption

Edit the my.cnf (/etc/mysql/my.cnf) file and add the following lines:

[mysqld]
innodb_force_recovery = 1

then run the command:

sudo systemctl start mysql

It may do not work for the first time and you need to increment the number to 2 or 3. I will be fixed finally. :-)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Anis Kaypooor