views:

170

answers:

1

This is driving me nuts! I am getting the classic "Can't connect to local MySQL server through socket '/var/run/mysql4d/mysql4d.sock' (13)".

Everything I've dug up so far tells me my setup should be OK (eg, defining the sockets in php.ini and my.cnf, etc). Worse... phpmyadmin works with the same un/pw I am using in my own php. So obviously it's possible to connect, but I am screwing it up

I tried reverse-engineering the connection from phpmyadmin, but gave up it as too convoluted after a couple hours.

Can anyone offer some advice?

My configuration: Ubuntu 9.10 (Karmic), Apache 2.2, PHP 5.2.6, MySQL 4.1.22 (for legacy app reasons).

my.cnf (/var/lib/mysql4/my.cnf):

[client]
port = 3306
socket = /var/run/mysql4d/mysql4d.sock
[mysqld]
port = 3306
socket = /var/run/mysql4d/mysql4d.sock

php.ini (/etc/php5/apache2/php.ini):

[MySQL]
mysql.default_socket = /var/run/mysql4d/mysql4d.sock
[MySQLi]
mysql.default_socket = /var/run/mysql4d/mysql4d.sock

Same problem using mysql instead of mysqli, btw.

EDIT: I should mention that I have installed mysql4 alongside the ubuntu default install of php & mysql for use with a legacy application and it is this installation that I am having trouble connecting with. I tried this:

ini_set('mysql.default_socket', '/var/run/mysql4d/mysql4d.sock');

and now the connection goes thru, but all queries return empty sets. (cries in frustration)

+1  A: 

This sounds like a permission problem in /var/run/mysql4d/mysql4d.sock. What user are you running this as? Are the permissions o.k. on file system level?

If you Google for the error messages, you'll find a lot of people who had this and it was always a permission issue, sometimes due to an activated SELinux. Check this thread for a few possible solutions.

Pekka
Hey Pekka, thanks for the tip! But I don't have selinux installed on my machine. Nothing on the thread was helpful, alas.If it is a permissions issue, tho, perhaps my apache.conf is badly written...
Logos
Hmm, too bad! Does the socket actually exist? Have you checked its permissions? Is the Apache user allowed to access it?
Pekka
Yup, socket exists: srwxrwxrwx 1 mysql4 mysql4 0 2010-01-01 14:15 /var/run/mysql4d/mysql4d.sock Apache must be allowed to access it, or phpmyadmin wouldn't work.
Logos
All right. Is it an option to bypass the socket? If it is, try connecting to 127.0.0.1 instead of localhost (see "Notes" in http://de2.php.net/manual/en/function.mysql-connect.php why). Maybe that helps. I'm off now till tomorrow. Good luck!
Pekka
Aha! I tried overriding to use tcp/ip with mysqli instead of mysql, and it suddenly started working! mysqli_connect('127.0.0.1', $un, $pw, $db, 3306); It *doesn't* work with mysql_connect (which is hilarious, as the docs mention it on the mysql_connect page but not mysqli_connect). Thanks for all your help, Pekka!
Logos