[ubuntu-za] Can't connect to local MySQL server

Alf Stockton alf at stockton.co.za
Wed Jan 28 12:13:13 GMT 2009


Neil Muller wrote:
> On Wed, Jan 28, 2009 at 01:06:42PM +0200, Alf Stockton wrote:
>>> Tried specifying "localhost" in the connection?
>>>
>>> mysql -h localhost -u root -p
>>>
>> That gives me:-
>>
>> root at general:~# mysql -h localhost -u root -p
>> Enter password:
>> ERROR 2002 (HY000): Can't connect to local MySQL server through socket 
>> '/var/lib/mysql/mysql.sock' (111)
> 
> This is an optimisation mysql does - connections to 'localhost' will be
> redirected over the socket. It's not that promimently discussed in the
> mysql docs, so it tends to cause a fiar number of 'Huh, what?' moments.
> 
> On Wed, Jan 28, 2009 at 12:22:02AM +0200, Alf Stockton wrote:
>> root at general:~# ls -al /tmp/mysql.sock
>> lrwxrwxrwx 1 root root 25 2009-01-28 10:18 /tmp/mysql.sock -> 
>> /var/lib/mysql/mysql.sock
>> root at general:~# ls -al /var/lib/mysql/mysql.sock
>> -rw-r--r-- 1 root root 0 2009-01-28 11:40 /var/lib/mysql/mysql.sock
> 
> Um - that's not a socket (lack of a leading 's' in the ls output is a
> giveaway here), so that's a problem (and the permissions look wrong to
> me anyway - it should usually be writeable and readbale by everyone, not
> just root). Somehow it's been created incorrectly. Removing this, and
> restarting the mysql server should fix the problem.
> 
After stopping mysqld I removed the /var/lib/mysql/mysql.sock and restarted 
mysqld but still cannot log on as follows:-
root at general:~# ps aux | grep mysql
root     25321  0.0  0.0   3944   604 pts/3    S    13:59   0:00 /bin/sh 
/usr/bin/mysqld_safe
mysql    25360  0.0  0.8  83296  9232 pts/3    Sl   13:59   0:00 
/usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql 
--pid-file=/var/run/mysqld/mysqld.pid --skip-external-locking --port=3306 
--socket=/var/run/mysqld/mysqld.sock
root     25362  0.0  0.0   5068   812 pts/3    S    13:59   0:00 logger -p 
daemon.err -t mysqld_safe -i -t mysqld
root     25442  0.0  0.0   5164   832 pts/3    R+   14:03   0:00 grep mysql
root at general:~# mysql -u root
ERROR 2002 (HY000): Can't connect to local MySQL server through socket 
'/var/lib/mysql/mysql.sock' (2)
root at general:~# mysql -u root -p
Enter password:
ERROR 2002 (HY000): Can't connect to local MySQL server through socket 
'/var/lib/mysql/mysql.sock' (2)
root at general:~# mysql -h 127.0.0.1 -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: 
YES)
root at general:~# mysql -h 127.0.0.1 -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
root at general:~# ls -al /var/lib/mysql/mysql.sock
ls: cannot access /var/lib/mysql/mysql.sock: No such file or directory


-- 
Regards,
Alf Stockton		www.stockton.co.za

You are destined to become the commandant of the fighting men of the
department of transportation.



More information about the ubuntu-za mailing list