ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

This error is most very common in mysql which trigger due to numerous reasons

Check if mysql services are up and running

[root@tibero tibero]# ps -ef|grep -i 'mysql'
root      2096  2084  0 22:58 pts/0    00:00:00 /usr/bin/python /usr/bin/yum install mysql -y
root      2342     1  0 23:05 pts/0    00:00:00 /bin/sh /usr/bin/mysqld_safe --datadir=/var/lib/mysql --socket=/var/lib/mysql/mysql.sock --pid-file=/var/run/mysqld/mysqld.pid --basedir=/usr --user=mysql
mysql     2444  2342  0 23:05 pts/0    00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --log-error=/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock
root      2467  2211  0 23:05 pts/0    00:00:00 /bin/sh /usr/bin/mysql_secure_installation
root      2543  2211  0 23:11 pts/0    00:00:00 grep -i mysql

Check if you have socket parameter specified in my.cnf file

[root@tibero tibero]# cat /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Check if the file exist in /var/lib directory

[root@tibero tibero]# ls -lrt /var/lib/mysql/mysql.sock
srwxrwxrwx 1 mysql mysql 0 Jul  1 23:05 /var/lib/mysql/mysql.sock

Restart mysql service

[root@tibero tibero]# service mysqld restart
Stopping mysqld:                                           [  OK  ]
Initializing MySQL database:  Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h tibero password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                           [  OK  ]
Starting mysqld:                                           [  OK  ]

Try change mysql login password and login

[root@tibero tibero]# /usr/bin/mysqladmin -u root -h tibero password oracle
[root@tibero tibero]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Use telnet to connect to mysql port

[root@tibero ~]# telnet 127.0.0.1 3306

Check if the port 3306 is up

[root@tibero ~]# netstat -tupln|grep '3306'
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      2201/mysqld

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s