Monday, December 26, 2005

MySQL error: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)

A friend of mine was getting the following error and called me up. After telling him how to fix it, I decided to post it here too.
Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)
The solution was simple, just start MySQL :)

Did you know you can help educate the world through your bookmarks? Join my alpha project featuring social media tools ( and share your bookmarks while educating the world.


Smile Dreamz said...

OS error code 13: Permission denied

Therefore, the above definitely not THE ONLY cause.

But, one of the cause.

Frankly Speaking! said...

Thanks Smile Dreamz for pointing it out. I wasn't able to publish your comment because I am in the process of moving.

Error code 13 can be caused if:

- user/host permissions are wrong
- file permissions are wrong
- mysql not running

Thanks again

Anonymous said...

there is another case when you get this error even if mysql server is running. You should check if you compiled PHP with --enable-sockets option

Anonymous said...

frankly speaking I have been looking for hours for a solution to the mysql.sock (13) error and with your three lines you provided enough clues as to how to correct the problem. In my case the problem was in fact a user (group) permission error and not any one the many other possible problems. Thanks again for your insight.

boris said...

With fedora 6 you need disable SE Linux !

Phil said...

Thanks, Boris for the big help.

I have Fedora 3 with SELinux enabled, which was also the problem. The solution was to set "SELINUX=disabled" on the the configuration file /etc/sysconfig/selinux.

More info about disabling SELinux here:

Anonymous said...

Re-iterating Phil,


Without you, I would never have thought of a potential problem with selinux enabled.
But indeed I had one.

Anonymous said...

mysql.sock (13) error

the true answer, it's here:

Anonymous said...

Tanks!! the solution for this problem is: DISABLE SELINUX

Andrew B said...

Thank you so much! I spent over an hour trying to find this problem. selinux was the problem.

It it helps anyone:
* I was connecting to a remote SQL server
* Connected to SQL server fine from other sources
* Connected fine from web server using mysql command line
* Connected fine from web server using php in command line mode
* Would NOT connect from web server using php from page running under apache

Guru said...

thanks a lot.. your solution was very useful. I tried many other options on my application but nothing worked. Simple yet very useful.