Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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/mysqld.pid --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.

Edit:

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: 127.0.0.1, State: LISTEN

Edit2: 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 ..
share|improve this question
    
Can you post the mysql command you're using to try connect too? –  Bart B Aug 6 '09 at 11:45
    
Does the socket exist in netstat/filesystem listings and do you have permissions to it? –  Dan Carley Aug 6 '09 at 12:02
    
Thanks, I've updated the question in response to your comments. –  ehsanul Aug 6 '09 at 12:36
    
You'll want to include information specifically about the socket. Because that will be favoured over TCP. –  Dan Carley Aug 6 '09 at 13:00
    
Sorry Dan, I'm clueless how to do that. I just used Ubuntu's Network Tools GUI to check the "Netstats" tab, which shows the service is active over tcp on port 3306. How do I get information about the socket? It seems to not exist, as you'll see in the latest edit. –  ehsanul Aug 6 '09 at 13:13

4 Answers 4

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)
share|improve this answer
    
Thanks, but I get the exact same error, referring to the same socket. The socket connection is over tcp anyways, and netstats shows it. –  ehsanul Aug 6 '09 at 13:09
    
I see your ended up fixing it via reboot; but using the -h option should force mysql client to use TCP rather than socket for the connection. –  Dave Drager Aug 7 '09 at 14:54

I've run into this problem with assuming the wrong the place for the sock file when I'm using client software that wasn't compiled with the same options as the server. (in my case, a binary distribution of PHP).

I'd first check to make sure that the client that's being run is actually the one you think you installed, and not some other version lying around.

If that's not it, you can either tell the server to write its socket file in the location the client's looking for it. In my.cnf's '[mysqld]' section, change or add:

socket=/var/run/mysqld/mysqld.sock

or, just put in a symlink. For my PHP problem, as it looks for it in /tmp, I've got a job that runs at startup to add the symlink.

share|improve this answer

I encountered such problems in the past, usually it comes down to the socket file not being writable/readable by the mysql user. Could you ls -al the /var/run/mysqld/ directory and check the mysqld.sock access rights.

Try: chown mysql:mysql /var/run/mysqld/

and

chmod 755 /var/run/mysqld/

and then

/etc/init.d/mysql restart

It should fix your issue.

[Edit2] Could you check the my.cnf, especially the socket path and the bind address and report back. The bind address should be 127.0.0.1 and the socket path should be the same.

share|improve this answer
    
Thanks a lot, it looks like there's no mysqld.sock to be found. I'm still clueless how to resolve this, so I've updated the question with the output of ls -al –  ehsanul Aug 6 '09 at 13:07
    
check my updated answer, it's probably an access right issue. –  olefebvre Aug 6 '09 at 13:42
    
I followed your instructions, but the problem has not changed at all. I get the same error message, and the output of "ls -al /var/run/mysqld/" is still the same, as noted in edit2 of the question. –  ehsanul Aug 6 '09 at 13:44
    
I've tried to "su root" as well as "su mysql" and then run the "mysql" command, but it's the same. I've also tried "mysql -u root -p", but that also gives the same error. –  ehsanul Aug 6 '09 at 13:55
    
have you just set up the mysql server or did you encounter the issue after rebooting ? –  olefebvre Aug 6 '09 at 13:56

If it's OpenSuse or SLES, I bet it's AppArmor causing the issue. Go into yast and disable it.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.