May 16th in Linux/Unix by .

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:

22 Comments

  • F Robson
    September 7, 2008
  • T Nguyen
    March 11, 2009
  • Putu Ananta
    March 20, 2009
  • sham
    October 23, 2009
  • pbu
    October 23, 2009
    • aldo
      March 9, 2011
  • charan
    December 1, 2009
  • AFTAB
    February 6, 2010
  • Shadid
    February 25, 2010
  • Robert
    May 18, 2010
  • andy
    July 6, 2010
  • Regg
    August 31, 2010
  • prajakta
    January 2, 2011
  • rob
    April 23, 2011
  • pranav
    June 17, 2011
  • sql sock
    July 19, 2011
  • Malith Mahiru
    July 22, 2011
  • Manoj Kumar Jindal
    October 8, 2011
  • tim viec lam
    October 11, 2011
  • Defy
    January 7, 2012
    • Defy
      January 7, 2012
  • Dan
    February 3, 2012

Leave A Comment.