Thursday, June 07, 2007

Can't connect to local MySQL server through socket '/tmp/mysql.sock'

This is a very frequesnt error message seen by most of the users.

Reason : The default location of the socket file is /tmp but for various reasons the instllation may place the mysql.sock file in different location e.g. /var/lib/mysql/

It is actually But the solution is simple.


Solution 1: Specify the mysql.sock file location explicitly


mysql --socket=/var/lib/mysql/mysql.sock ...



Note : You could define an alias to avoid more typing.

Solution 2 : Update MySQL Configuration file /etc/my.cnf

Open the file using a text editor (vi) and go to client section. Update/Add socket variable value.



mysqld]
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock

[mysql.server]
user=mysql
basedir=/usr/local/mysql

[client]
socket=/var/lib/mysql/mysql.sock


If there is not currently a section called [client], add one as in above section.

You won't need to restart your server or any other processes.

No comments: