Wednesday, July 23, 2008

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

Since some time I was having troubles connecting to the MySql server running on local machine via command line. First I have to tell you that I’m not a Linux guru. Just started using it because my University forced me do so.
Anyway this was the symptom when I tried to access MySql server via command line interface.
By the way I was using Ubuntu 7. Something.

root@local:~# mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
root@local:~#


Browsing through more than 1 million search results ( : ) ) brought by Google didn’t bring anything valuable but only to discover that more than half of the world population is faced with the same issue.

Surely something is wrong. Either /tmp/mysql.sock is not in the place mysql utility is looking or it has been locked or something.
When i restarted MySql server (Of cause after brutally killing all by using # killall -9 mysqld) I discovered something interesting.


root@local:~# mysqld
080723 7:38:36 InnoDB: Started; log sequence number 0 43655
080723 7:38:36 [Note] Recovering after a crash using /var/log/mysql/mysql-bin
080723 7:38:36 [Note] Starting crash recovery...
080723 7:38:36 [Note] Crash recovery finished.
080723 7:38:37 [Note] mysqld: ready for connections.
Version: '5.0.45-Debian_1ubuntu3-log' socket: '/var/run/mysqld/mysqld.sock' port: 3306 Debian etch distribution

Aha …. Mysql server creates its socket in ‘socket: '/var/run/mysqld/mysqld.sock' ... Not the place mysql utility is looking for it.
Anyway since all got cleared now I had 2 paths. Mucking with some configuration file buried deep with in or compiling MYsql with
some wired flags set to change its default sock path. I had time to chose none. Hell I just wanted to run some damn small query on the database and say ta to MySql for good. So this is the final option I choosed.
In MySql utility there is a option called --protocol. I just used that.


root@local:~# mysql --protoco TCP -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.45-Debian_1ubuntu3-log Debian etch distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>

Bye Bye stinky Sock ... Welcome TCP Socket. Problem not solved but successfully overlooked. Well that’s enough for me at the moment.

No comments:

Post a Comment