May 16th in Linux/Unix by pbu .

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:

Share and Enjoy:
  • del.icio.us
  • digg
  • StumbleUpon
  • Technorati
  • DZone
  • Facebook
  • FriendFeed
  • Reddit
  • RSS
  • Twitter

11 Comments

  • F Robson
    September 7, 2008
  • T Nguyen
    March 11, 2009
  • Putu Ananta
    March 20, 2009
  • sham
    October 23, 2009
  • pbu
    October 23, 2009
  • charan
    December 1, 2009
  • AFTAB
    February 6, 2010
  • Shadid
    February 25, 2010
  • Robert
    May 18, 2010
  • andy
    July 6, 2010
  • Regg
    August 31, 2010

Leave A Comment.