Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' in Ubuntu 12.04.5 LTS

Here is what fixed for me with Mariadb

First find out if your mysql config file ,most likely located at /etc/mysql/my.cnf or /etc/my.cnf has the correct mysql.sock entry or not

You can find out where mysql.sock file is located by running find / -type s , if the entry is not correct in your mysql config, file fix it , also make sure mysql.pid has the correct path as well.

Now try to start mysql server , if it starts fine and you can see all DB's and tables within , you are good and dont need to follow rest of the post .

If mysql fails to start after fixing mysql.sock path , read on

Add the following to your my.cnf file ,

innodb_force_recovery = 1 inside the mysqld block , and restart mysql.

If it fails to start , increment the number by one each time , but keep in mind , after 3 , their might be some data loss (not happened to me , but i have only read about anything above 3 being a salvaging measure , than a recovery)

Dont panic if some of the tables you previously had , stop showing that they dont exist in the engine . Ones mysql starts successfully (if you dont have a backup yet , better make one now , just in case things go south from here on) , remove innodb_force_recovery = 1 from my.cnf file and restart mysql again , all your tables should be available again.

Posts that helped me

  • https://stackoverflow.com/a/20617180/3117013
  • https://stackoverflow.com/a/11990813/3117013