Resolvendo problema de socket no mysql

The problem

For Several times this has happened to me, always install a new server, or personal machine. I install mysql , and time to connect:

The solution

Simple and easy, look for the configuration file, my.cnf, make sure it is the same configuration file.

Make a backup of it, to avoid any problem. My use is as ubuntu /etc/mysql/my.cnf

Edit the uncompensated you will get the following lines:

Ensure that the user that is experiencing the error, allowed reading /var/run/mysqld/mysqld.sock

If it does not give permission.


If you are trying to connect with php. And is getting the error, it may be that in your php.ini is set, an socket .

To resolve just open php.ini

This path may vary according to the php you are using, in my case I use lighttpd with php-cgi , and this is the default path.

For those who do not know is how to use php or lighttpd not know, you can take a look here: Enabling PHP on lighttpd without difficulties . Enable it, and see how the fastcgi can be much faster.

After opening the file, search for mysql.default_socket put the correct path, or leave blank.

What’s the use?

The speed difference between the connection is quite large, if you pass the direct path of the socket connects much faster, especially if the socket is in tmpfs.

For those who do not know what is tmpfs, you can learn more at this link: Improving performance of linux


mysql –
php –
php – stackoverflow

Written by vinicius