[RESOLVED] Error "Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

[RESOLVED] Error "Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)

This problem occurs when you run command "# mysql -u USER -p". It happens as MySQL is not running or installed on server. To rectify this we have first check whether MySQL is running or not.

To check MySQL is Running or not type the following command:
----
# service mysqld status
----

You can run MySQL if is not running :
----
# service mysqld start
----

To check MySQL is installed or not run this command :
----
# rpm -qa mysql-server
----

If this doesn't solve your problem Then Follow these below given steps.

1). First, kindlty take backup the /var/lib/mysql directory. In case if anything goes wrong.
----
# cp -fr /var/lib/mysql /var/lib/mysql.old
----

2). Now check for .sock file in these places "/var/lib/mysql" and "/tmp" :

3). You have to recreate the symbolic link to the .sock file:
----
# ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
----

4). Check the permissions of the "/var/lib/mysql". It should be 0755 and mysql:root. If it is not then run these command :
----
# chmod 0755 /var/lib/mysql
# chown mysql:root /var/lib/mysql

----

5). Check for mysql user is there in /etc/passwd

6). Check for /var/lib/mysql/mysql/host.MYI exist or not ? If not present then run these commands :
----
# chmod -R 0660 /var/lib/mysql/mysql
# chown -R mysql:mysql /var/lib/mysql/mysql
# /usr/bin/mysql_install_db

----

7. Force update MySQL :
----
# /scripts/mysqlup --force
----

If all above didn't sort out your problem then run this below given command :
----
# /usr/sbin/mysqld --basedir=/ --datadir=/var/lib/mysql --user=mysql --pid-file=/var/lib/mysql/Server_HostName.pid --skip-locking &
----
Author
bhawanisingh
Views
5,575
First release
Last update
Rating
0.00 star(s) 0 ratings
Top