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!
Similar Posts:
- how to create new user for phpmyadmin login
- Install LAMP Server for Centos/RHEL
- Install FTP Server for Centos/RHEL
- BSNL Dataone – Common Error Messages & Code Numbers
- Single/double quotes causes error in mysql INSERT query!
- BSNL Error 691 – Access was denied because username/password was invalid on the domain
- easyapache -Premature end of script headers error in cpanel
- How to upload/download files with FTP in linux commandline
- how to store and retrieve checkbox value in php?
- Tataindicom Plug2surf Internet not working!





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
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!