Short description:
I tried to install D7 on a hosted service. This failed with the error:
Failed to connect to your database server.
The server reports the following message:
SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysql-5/mysql.sock' (2)

I removed D7.0-rc2 and replaced it with D6.20 This one installed flawlessly.

Not sure if this bug report should be made critical as fully blocks the installation of D7, where it is possible to install D6.

I can access the database without problem using PMA (phpMyAdmin), and via the command line. The only sofar that has a problem accessing the database is D7.

The good news is that the Service Provider made it work by adding a link on system, more about that below. After this soft link was made, I was able to install D7 without a problem.

Some information about the hosted environment, which hopefully reveals what is causing the problem with the installation of D7.
- mysql5 has been configured to use the socket in /var/run/mysql5/mysql.sock (without "-")
# grep -E "socket|^\[" my.cnf
[client]
socket = /var/run/mysql5/mysql-5.sock
[mysqld]
socket = /var/run/mysql5/mysql-5.sock

mysql5 is installed and run from /usr/local/mysql-5. This is the place where my.cnf is located as well (to be precise: /usr/local/mysql-5/etc/my.cnf). On the same server mysql4 is running too.

mysql runs with the following socket value (output from ps):
/usr/local/mysql-5/bin/mysqld ...... --socket=/var/run/mysql5/mysql-5.sock

Where comes the mmysql-5/mysql.sock in the error message from? Why does D7 think that it should /var/run/mysql-5/mysql.sock, while the correct value is: /var/run/mysql5/mysql-5.sock?

The service provider solved the problem temporarely (until the next reboot) with a soft link as follows:
# ls -ld /var/run/mysql-5/m* /var/run/mysql5/m*
lrwxrwxrwx 1 root root 28 2010-12-22 13:44 /var/run/mysql-5/mysql.sock -> /var/run/mysql5/mysql-5.sock
srwxrwxrwx 1 mysql daemon 0 2010-12-21 13:19 /var/run/mysql5/mysql-5.sock
The last one is the socket configured in my.cnf. The first is the link to make D7 installable.

It's showstopper for me, might a showstopper for others too!

CommentFileSizeAuthor
#6 install.inc_.patch1.28 KBradoeka

Comments

radoeka’s picture

phpinfo gives the following compiled in mysql information:
Client API library version 5.1.47
MYSQLI_SOCKET /var/run/mysql5/mysql-5.sock
mysqli.default_socket /var/run/mysql5/mysql-5.sock

yukare’s picture

Look at these settings on your php.ini. May be your server have set one different of other. Drupal 6 uses mysql and Drupal 7 uses pdo

mysql.default_socket
pdo_mysql.default_socket

Another solution is to install using 127.0.0.1 for the host, instead of localhost.

radoeka’s picture

This one pdo_mysql.default_socket is not set. Can that be the reason?

w3m -dump http://my_website/phpinfo.php | grep -i pdo

PDO
PDO support enabled
PDO drivers mysql, sqlite, sqlite2
pdo_mysql
PDO Driver for MySQL enabled

What is the result when pdo_mysql.default_socket is not set? Does it use the value that it shows in the error message (/var/run/mysql-5/mysql.sock)?

> Another solution is to install using 127.0.0.1 for the host, instead of localhost?

Why would that be a solution? If the socket is linked to the address expected by Drupal it is working => if localhost would be the cause of the error, than the error would also show up with the link being present (I think).

I can't test this solution now, as the link is present and I have no control over that link (it is not my machine).

radoeka’s picture

Problem is described in this php bug report http://bugs.php.net/50829

I assume that more people will run into this problem.

yukare’s picture

Because when you connect using localhost, the connection is made on a socket, and when you connect using 127.0.0.1 it connects by ip and port, in this case it uses the same way as if the mysql server and apache are not in same machine.

radoeka’s picture

Issue tags: +mysql connect failure
StatusFileSize
new1.28 KB

@yukare: thanks for the explanation. It makes sense what you state, thanks you.

For the record there are more issues with this problem:
http://drupal.org/node/936008
http://drupal.org/node/752856
http://drupal.org/node/899940

This one http://drupal.org/node/793200 this to me main bug report for this problem.

Ain't it possible to improve the error message and add a line that states that 127.0.0.1 can be used instead?

Patch attached. The Patch adds the following line:
- If all of the above are correct and you've used localhost for the system where the database resides; try to use 127.0.0.1 instead of localhost, this may solve the problem

Crell’s picture

If we go this route we should probably specify why that may correct the error, at least in general terms. However, this would be a string change so I'm not sure if we can do so at this point given that we're well past RC. Webchick would have to green-light that.

catch’s picture

Title: Regression: critical? can not install D7 error: Can't connect to local MySQL server through socket /var/run/mysql-5/mysql.sock » Document PDO bug with mysql sockets
Version: 7.0-rc2 » 7.x-dev
Category: bug » task
Status: Active » Closed (duplicate)