PDA

View Full Version : Database error - can't connect to local MySQL server through socket


leannet
05-27-2013, 10:45 PM
Does this error just happen or does it mean some one has been messing with the site?

<!--
Database error in vBulletin :

mysqli_real_connect() [&lt;a href='function.mysqli-real-connect'&gt;function.mysqli-real-connect&lt;/a&gt;]: (HY000/2002): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
/home/----------/public_html/includes/class_core.php on line 1138

MySQL Error :
Error Number :
Request Date : Monday, May 27th 2013 @ 06:37:23 PM
Error Date : Monday, May 27th 2013 @ 06:37:23 PM
Script : http://-------------.com/admincp/index.php
Referrer :
IP Address : 175.35.66.88
Username :
Classname : vB_Database_MySQLi
MySQL Version :
-->

--------------- Added 1369698881 at 1369698881 ---------------

I found this answer

If you are getting this error, it means either:

1. The info in your config.php file is wrong (in which case your forums wouldn't work at all), or

2. MySQL crashed, it's not running or it can't find the socket. You need to contact your host about this.



What if I can't contact my host ?

skol
05-27-2013, 11:48 PM
When connecting to a MySQL server located on the local system, the mysql client connects through a local file called a socket instead of connecting to the localhost loopback address 127.0.0.1. For the mysql client, the default location of this socket file is /tmp/mysql.sock. However, for a variety of reasons, many MySQL installations place this socket file somewhere else like /var/lib/mysql/mysql.sock.

While it is possible to make this work by specifying the socket file directly in the mysql client command.

mysql --socket=/var/lib/mysql/mysql.sock ...

Problem with that you would be adding it constantly.

You can make a simple change to the MySQL configuration file /etc/my.cnf that will permanently set the socket file used by the mysql client. After making a backup copy of /etc/my.cnf, open it in your favorite editor. The file is divided into sections such as..

[mysqld]
datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock

[mysql.server]
user=mysql
basedir=/usr/local/mysql

If there is not currently a section called [client], add one at the bottom of the file and copy the socket= line under the [mysqld] section such as:


[client]
socket=/var/lib/mysql/mysql.sock

If there is already a [client] section in the my.cnf file, add or edit the socket line as appropriate. You won?t need to restart your server or any other processes. Subsequent uses of the mysql client will use the proper socket file.