Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I encountered with the error Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' in Ubuntu 12.04.5 LTS. So,I uninstalled mysql 5.5 from Ubuntu 12.04.5 LTS.But when i tried to install mysql,i was unable to install mysql.

i used the following commands to uninstall mysql:

 sudo apt-get remove --purge mysql-server mysql-client mysql-common
 sudo apt-get remove --purge mysql-server-5.5 mysql-client-5.5 mysql-servercore-5.5 mysql-client-core-5.5
 sudo apt-get autoremove
 sudo apt-get autoclean
 sudo rm -rf /var/lib/mysql
 sudo rm -rf /etc/mysql
 sudo deluser mysql

I used the following commands to install mysql 5.5:

sudo apt-get install mysql-server-5.5
sudo apt-get install mysql-server

But i was encountered with the following error:

 AppArmor parser error for /etc/apparmor.d/usr.sbin.mysqld in      /etc/apparmor.d/usr.sbin.mysqld at line 9: Could not open 'abstractions/mysql'
 start: Job failed to start
 invoke-rc.d: initscript mysql, action "start" failed.
 dpkg: error processing mysql-server-5.5 (--configure):
subprocess installed post-installation script returned error exit status 1
dpkg: dependency problems prevent configuration of mysql-server:
mysql-server depends on mysql-server-5.5; however:
Package mysql-server-5.5 is not configured yet.
dpkg: error processing mysql-server (--configure):
dependency problems - leaving unconfigured
No apport report written because the error message indicates its a followup    error from a previous failure.
                                                                                                         Errors were encountered while processing:
mysql-server-5.5
mysql-server
E: Sub-process /usr/bin/dpkg returned an error code (1)

When i type 'mysql' from terminal it returns the error:

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

I tried telnet 127.0.0.1 3306 after googling,it returned connection refused.

Can anyone please suggest a solution?

like image 803
titto.sebastian Avatar asked Aug 20 '15 10:08

titto.sebastian


People also ask

Can't connect to MySQL server through socket Ubuntu?

To fix the MySQL socket issue and access denied error for root@localhost , follow the below steps. Stop the MySQL server by executing the command “ sudo service mysql stop “. Create socket location as a placeholder by executing the command “ sudo mkdir -p /var/run/mysqld “.

Can not connect to MySQL server through socket?

Try to connect to 127.0.0.1 instead of localhost If you connect to localhost , it will use the socket connector, but if you connect to 127.0. 0.1 the TCP/IP connector will be used. So when the socket connector is not working, try connecting to 127.0. 0.1 instead.

Can't connect to local MySQL server through socket '/ var run MySQL sock 2 No such file or directory?

Another possible solution to the >can't connect to local mysql server through socket> error message is to try and connect to the MySQL using the 127.0. 0.1 ip address instead of localhost. When you use localhost to connect to MySQL, the operating system uses the socket connector. However, if you use 127.0.


2 Answers

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
like image 129
Golu Avatar answered Oct 14 '22 00:10

Golu


In my case it was because the system memory RAM did not have enough space for the "free -hw" database, I was able to solve it with the use of swap

like image 37
Domp Avatar answered Oct 14 '22 00:10

Domp