Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I got this error on my php script with db:

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

and on phpmyadmin:

#2002 Cannot log in to the MySQL server

What is the problem, how can i fix this? I have installed lamp-server..

share|improve this question
If the answer below does not fix it, it would be advisable to show your php code. – medigeek Dec 28 '11 at 12:50
related question ->… – hhlp Dec 28 '11 at 13:12
When i use myql -u root -p i get message that it cant connect. – Mirza Delic Dec 28 '11 at 17:25
up vote 3 down vote accepted

It seems that the mysql server is not running.

In a normal mysql installation, you can check if the server is running with the following command: service mysql status

For starting it, just run service mysql start.

share|improve this answer
It is running, i checked. Any other solution ? Can i reinstall only mysql, but i have installed lamp server, so it work make any difference to other modules ? And please give me commands to reinstall mysql – Mirza Delic Dec 28 '11 at 17:49
Could you check what happens after restarting the server? (service mysql restart) – el.atomo Dec 28 '11 at 18:11
I checked that, but i fixed this with uninstaling mysql-server and mysql-common, then i installed mysql-server and phpmyadmin, and it works, now.. Thanks. – Mirza Delic Dec 28 '11 at 22:18
Kubuntu 13.04 mysql: unrecognized service – Green Jul 20 '13 at 20:52
Ok, just for information, I had to use sudo mysql start in order to make it work. This answer seems to solve the problem. Thank you very much. :) – Geppettvs D'Constanzo Oct 10 '13 at 19:06

In my case, I didn't even have the file, so any mysql command wouldn't work. I had to run mysqld_safe to create a new mysqld.sock file. That is:

$ cd /etc/init.d/
$ mysqld_safe

You'll probably won't get prompt back, but if you restart your session, a mysqld.sock file will be somewhere. Find it with

$ sudo find / -type s | grep mysqld.sock
share|improve this answer

Under Ubuntu 14.04 this is running but the socket is not nor the file present. Replace your database connection host to =

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.