Fix: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’
if you are new to installing mysql server you might probably face this error quite often if you type mysql in the shell prompt.
> mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
To fix:
First start the mysql daemon, then type mysql
> /etc/init.d/mysqld start
> mysql
Bingo! It worked for me!
To update mysql root password
mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD('new-password') WHERE user='root';
mysql> FLUSH PRIVILEGES;
To add a new user to mysql
1. First login as root then create a database ‘demo’
> mysql -u root -p
Enter password:
mysql> create database demo;
After that create a new user named ‘guest’ with password ‘guest’ with all previleges assigned to demo database;
mysql> GRANT ALL PRIVILEGES ON mytest.* TO 'guest'@'localhost' IDENTIFIED BY 'guest' WITH GRANT OPTION;
Then exit mysql and connect through username guest;
That should work!
Note: This could happen, if you run out of your disk space. Check your disk space.
Similar Posts:
- how to create new user for phpmyadmin login
- Install LAMP Server for Centos/RHEL
- Install FTP Server for Centos/RHEL
- Server not responding and cant login to SSH!
- Which linux command to find free disk space!
- Fix -> MySQL LOAD DATA Infile – Access Denied using password YES
- How to use LOAD DATA INFILE to import fixed width data in MySQL
- BSNL Dataone – Common Error Messages & Code Numbers
- How to upload/download files with FTP in linux commandline
- easyapache -Premature end of script headers error in cpanel



September 7, 2008
thanks very much for the clear and simple instructions – it solved my problem nicely.
March 11, 2009
Great Instruction, i solve my problem. Thanks!
March 20, 2009
thank you……
October 23, 2009
I run as u said..
/etc/init.d/mysqld start
didsnt work it says
“-bash: /etc/init.d/mysqld: No such file or directory”
October 23, 2009
try this:
service mysqld restart
March 9, 2011
service mysql start
works for me
December 1, 2009
thanks it solved my problem
February 6, 2010
/usr/bin/mysql start
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
[root@ser-man1 ~]# whereis mysqld.sock
mysqld:
[root@ser-man1 ~]# mysql –print-defaults
mysql would have been started with the following arguments:
[root@ser-man1 ~]#
[root@ser-man1 ~]# /etc/init.d/mysql start
bash: /etc/init.d/mysql: No such file or directory
[root@ser-man1 ~]# find / -name “mysqld”
[root@ser-man1 ~]# find / -name “mysqld”
[root@ser-man1 ~]# mysql –socket=/var/run/mysqld/mysqld.sock
^[[3~ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
[root@ser-man1 ~]# mysql –socket=/var/run/mysqld/mysqld.sock
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2)
[root@ser-man1 ~]# /etc/init.d/mysqld start
bash: /etc/init.d/mysqld: No such file or directory
[root@ser-man1 ~]# mysql
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
[root@ser-man1 ~]# service mysqld restart
mysqld: unrecognized service
[root@ser-man1 ~]# service mysqld stop
mysqld: unrecognized service
[root@ser-man1 ~]#
I tried almost all given in the sites,but none of them worked for me. I have Cent OS 4.8 (Final)
I need help on this
February 25, 2010
Nothing worked for me until I tried this one from http://forums.mysql.com/read.php?11,27769,59865#msg-59865
There are two things that could go wrong here:
1. You don’t have permissions to access the directory /var/lib/mysql/whatever.sock because mysql is the owner of the folder
or
2. /path/whatever.sock doesn’t exist.
You can try this though [Linux specific, but what other operating systems are there?]
Go to /etc/my.cnf and change/add the lines:
[mysqld]
datadir=/var/lib/mysql
socket=/tmp/mysql.sock
[client]
socket=/tmp/mysql.sock
This way the client and server use the same socket and it’s in a public directory. This solves my MySql problems 98% of the time.
May 18, 2010
lol WELL IT WASNT THE ANSWER BUT IT GAVE ME ENOUGH ERRORS TO TAKE OVER FROM THAT…. Had to bond to 127.0.0.1 since I was copying a server…
Thanks
July 6, 2010
Thanks mate. Funny how something so simple can confound you for so long!!
Cheers
Andy
August 31, 2010
Thank You .. spent hours trying to reconcile myself. Your fix did the trick in seconds. Really appreciate it!
January 2, 2011
Even after doing the procedure below
[mysqld]
datadir=/var/lib/mysql
socket=/tmp/mysql.sock
[client]
socket=/tmp/mysql.sock
I get the same error message
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (111)
April 23, 2011
These clear instructions were just what I needed–many thanks!
June 17, 2011
thank a lot ..
July 19, 2011
‘None of the above’ worked for me.
Two years on and i’m still getting the same old error!
July 22, 2011
I had the same issue when there was no enough disk space.
October 8, 2011
>/etc/init.d/mysql start
>mysqldump -u[usrname] -p[password] -databases -r[result-file-with-path]
worked for me as well
thanks
manoj
October 11, 2011
I had the same issue when there was no enough disk space.
January 7, 2012
I just write this:
apt-get purge mysql-server*
and it’s helping
January 7, 2012
Sorry i was wrong, it doesn’t help
February 3, 2012
I got mine working.
You have to also install mysql-server:
yum install mysql-server
Then restart the service:
service mysqld start
and connect.