Skip to main content

[Solved] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock

Many a time working with MySQL in Ubuntu servers you may have faced problem "can't connect to local Mysql Server through socket /var/run/mysqld/mysqld.sock'

I was working on Ubuntu 14.04 64bit server, where I installed Mysql server and hosted database application to run on it.

One day I tried to reset root password of my Cloud Virtual Server, when I reset the root password of the server, suddenly after reboot, MySQL stopped working.

I was getting error like "ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)"

This means that Mysql was unable to start because there were files missing in /run/mysqld

/run/mysqld     socket files
I found that both and mysqld.sock files were missing , I don't know why but they were missing that is why I was getting error message as stated above.

I somehow I wanted to create these two files again so that I can resolve this issue.
Reinstalling of mysql server was not an option as I was unaware about the database files which were already there in server.

So to resolve this issue I followed below steps and the Issue was resolved.

1) Try to run this command
ps -A|grep mysql
This will show you mysql process running and we have to kill that process.

2) Now kill the running mysql process, use this command
sudo pkill mysql
This will kill mysql process.

3) Now kill the mysqld process
ps -A|grep mysqld
sudo pkill mysqld

4) Now you are ready to restart your mysql services as already running mysql processes are killed.

sudo service mysql restart
Once your mysql service is restarted , you can see that those missing files are created at /run/mysqld .

Now you will not get the error message "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock" as socket files are created successfully.

Hope this tutorial helps you in resolving issue of mysql connection throug socket.

To improve this article you can comment below with your views.

Thanks for reading.


Popular posts from this blog

SpiderHost with Powerful & Low Cost Dedicated Servers

We are glad to inform you that, we are providing total 4 Dedicated Servers at very very low cost , & hosted in Tier3 & Tier 4 Datacenters across asia.

Please check below given details to buy Dedicated Server.

visit to buy servers.

Payment Accepted:

1. Paypal
2. CCAvenue for Indian Customers
3. 2 Checkout for Customers worldwide.

Sales Team,
SpiderHost - Asia's Leading Web Hosting Company

Cpanel Tutorial


SpiderHost cares for their customers that's why we have brought you the Cpanel Tutorial and Knowledgebase on youtube.

Now you can learn

1. How to do Web Hosting in Cpanel
2. How to create Mysql Database in Cpanel
3. How to create Email Accounts in Cpanel
4. How to install wordpress in cpanel using 1 click
5. How to manually install wordpress in cpanel
6. How to backup your complete cpanel or partial backups in cpanel


Kindly Subscribe to our Channel so that you can get updates properly