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

Possible Duplicate:
My MySQL installation is broken. How to completely reconfigure it?

When i try to login in apache i get a #2002 error. When i try to login in MySQL via terminal it ask my password and i get:

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

I tried to remove mysql and install it again and nothing happen ( i cant even remove it) I try to reboot apache but still nothing. I tried to reboot my pc and of course still aint working.

In terminal i get this:

$ sudo start mysql
start: Job failed to start

$ mysql -ubob -hlocalhost -P3306 -p
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

$ sudo service mysql stop
stop: Unknown instance: 

Here is my my.cnf file:

# * Basic Settings
user        = mysql
pid-file    = /var/run/mysqld/
socket      = /var/run/mysqld/mysqld.sock
port        = 3306
basedir     = /usr
datadir     = /var/lib/mysql
tmpdir      = /tmp
lc-messages-dir = /usr/share/mysql

I tried to find if there is a file in my /var/run/mysqld/ or in /var/tmp/ and dint find the file mysqld.sock... I looked in /var/log/mysql/ and don't even have anything in it.

Can you help me? I try to find help on google for hours and din't help at all...

More info:

Result of cat /var/log/syslog | grep mysql here

/var/run/mysqld/ exists but it doesn't have anything in it

$ ls -la/var/run/mysqld/
total 0
drwxr-xr-x  2 mysql root  40 Nov 5 22:31 .
drwxr-xr-x 25 root  root 860 Nov   5 22:32 ..

my ubuntu is 12.04 LTS . can you tell me how can i make backups of my databases too?if you dont have something better then reinstall at least i can backup my databases

i tried to make backup with following:

mysqldump -u root -p –all-databases > all_backup.sql

Enter password:

mysqldump: Got error: 2002: Can't connect to local MySQL server through socket >'/var/run/mysqld/mysqld.sock' (2) when trying to connect

share|improve this question

marked as duplicate by hhlp, belacqua, Jorge Castro, Ringtail, stephenmyall Nov 7 '12 at 9:30

This question was marked as an exact duplicate of an existing question.

have you tried this ->… – hhlp Nov 6 '12 at 16:08
up vote 0 down vote accepted

I guess you don't have MySQL running. Try start it using

 $ sudo service mysql start

If you still get errors check in the syslog for some info

$ grep mysql /var/log/syslog 

If you can't figure the problem you can also update your answer with the log using pastebinit

$ grep mysql /var/log/syslog  | pastebinit

Also, check that /var/run/mysqld/ directory exists and belogs to mysql user.

$ ls -la /var/run/mysqld
total 4
drwxr-xr-x  2 mysql root   80 Nov  5 21:24 .

If nothing solves the problem, maybe the best way is to completely remove MySQL and install it again.

WARNING: this will delete all your MySQL data. So if you have important data in MySQL databases you should make a backup first!

sudo apt-get purge mysql-server mysql-common
sudo rm -rf /var/lib/mysql
sudo apt-get clean
sudo apt-get install mysql-server


I found this bug which seems similar to yours. There's a workaround there by Simon Hill that may work with you: creating a file /etc/apparmor.d/tunables/proc (if it dont already exists) with the following content:

# ------------------------------------------------------------------
#    Copyright (C) 2006 Novell/SUSE
#    This program is free software; you can redistribute it and/or
#    modify it under the terms of version 2 of the GNU General Public
#    License published by the Free Software Foundation.
# ------------------------------------------------------------------

# @{PROC} is the location where procfs is mounted.
share|improve this answer
i edit it check it out – Systeem Faillure Nov 5 '12 at 22:27
@SysteemFaillure i've updated the answer, but before you try to remove MySQL update your question with your Ubuntu version (you can get it using cat /etc/issue). Maybe with this someone can give you a better solution. – Salem Nov 6 '12 at 13:25
Salem i update my answer.if you dont have any better solution tell and i will remove mysql (but also tell me how can i make backup) and stay in touch if something goes wrong with the remove – Systeem Faillure Nov 6 '12 at 14:04
you can't make a backup because the server can't run. To backup your data files: sudo cp -r -p /var/lib/mysql <backup_location> – Salem Nov 6 '12 at 16:07
ok my phpMyAdmin is running great again!! 3 more questions thought: How can i restore my database? is just sudo cp -r -p <backup_location> /var/lib/mysql ?? The file you told me to create what extansion must have? (.conf or what?) And any ideas on how i can protect my self from error #2002 in the future? Thanks allot mate for you help and your time! :) – Systeem Faillure Nov 6 '12 at 16:41

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