Correcting mysql.sock connection error
For Several times this has happened to me, always install a new server, or personal machine. I install mysql , and time to connect:
Can not connect to local MySQL server through socket '/var/mysql/mysql.sock' (38)
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
cd /etc/mysql/ cp my.cnf my.cnf.bkp
Edit the uncompensated you will get the following lines:
[mysqld] # # * Basic Settings # socket = /var/run/mysqld/mysqld.sock port = 3306 basedir=/usr
Ensure that the user that is experiencing the error, allowed reading /var/run/mysqld/mysqld.sock
If it does not give permission.
MySQL + PHP
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 – http://www.mysql.com/
php – http://www.php.net/
php – stackoverflow
Leave a Comment