Mysql – Problem running thesql client, cannot connect to thesql server


Edit3: Thanks for the help everyone. Sorry for wasting anybody's time, but it seems like a simple reboot solved it. I should've known better, but I just had the assumption that the "restart" solution is mostly valid just for MS Windows (no offense). I'll keep this in mind before I ask a question here again.

I installed the mysql-client-5.0 and mysql-server-5.0 packages on Ubuntu 8.04, using sudo apt-get install.

When I try to run the "mysql" command, I get the following error:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

To verify that mysql server is running, I tried this, and it does seem to be running, with the correct socket too:

$ ps aux | grep mysql
root     13388  0.0  0.0   1772   528 ?        S    06:24   0:00 /bin/sh /usr/bin/mysqld_safe
mysql    13553  0.0  1.4 127012 15332 ?        Sl   06:25   0:00 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --user=mysql --pid-file=/var/run/mysqld/ --skip-external-locking --port=3306 --socket=/var/run/mysqld/mysqld.sock
root     13555  0.0  0.0   3008   696 ?        S    06:25   0:00 logger -p daemon.err -t mysqld_safe -i -t mysqld
ehsanul  16910  0.0  0.0   3092   772 pts/4    R+   07:17   0:00 grep mysql

So I don't understand why I'm getting an error trying to connect to mysql server. Note that I'm completely new to mysql.


As requested in comments, the exact command that is returning the error is simply "sudo mysql".
And when I check netstats for active networks services, I do see an entry for port 3306, with Protocol: tcp, IP Source:, State: LISTEN

It appears as if the /var/run/mysqld/mysqld.sock socket doesn't exist (if I'm interpreting the following output correctly):

$ ls -al /var/run/mysqld/
total 0
drwxr-xr-x  2 mysql root  40 2009-08-06 06:36 .
drwxr-xr-x 20 root  root 860 2009-08-06 06:25 ..

Best Answer

If you are having problems connecting through socket, you may try connecting to your mysql server via tcp:

mysql -h localhost

Or using username/password:

mysql -h localhost -u root -p

Either one may work depending on how the users are set up. If you get this error it means that the mysql command is at least talking to the server:

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
Related Topic