You are here

Document OS X PDO socket installation issues

I am getting this error when trying to do a fresh install of d7 alpha-3 but not alpha-1 or any previous dev releases as I have been able to install those. It is also present in the latest dev release. Attached is the phpinfo() output from my server. I am sorry that I can not provide more detail at the moment as my knowledge about PDO is limited, tell e what I should do and I will happily provide more info.

Error message

Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in DatabaseConnection->__construct() (line 315 of /Library/WebServer/Documents/includes/database/database.inc).

Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in DatabaseConnection->__construct() (line 315 of /Library/WebServer/Documents/includes/database/database.inc).

Warning: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in DatabaseConnection->__construct() (line 315 of /Library/WebServer/Documents/includes/database/database.inc).

In order for Drupal to work, and to continue with the installation process, you must resolve all issues reported below. For more help with configuring your database server, see the Installation and upgrading handbook. If you are unsure what any of this means you should probably contact your hosting provider.

Failed to connect to your MySQL database server. MySQL reports the following message: SQLSTATE[HY000] [2002] No such file or directory.

I am able to install both Alpha3 and the latest dev with no problems, Niklas. On Mac OSX. I will let others chime in here, but I don't believe this should be critical. From the looks of that error message it appears something may be configured improperly on your setup.

@webkenny,
I have been trying to find out more on this. I have never considered any config errors because I have had a production site running Drupal 6.2-6.16 (and some minor home-brewed stuff) flawlessly on the same machine as well as installed some 7.x-dev releases in late 2009 without any database-related issues. MySQL had been installed via the OS X disk image downloaded from the mysql homepage.

Well, what I found that might be interesting is:

MySQL Admin reports "socket = /tmp/mysql.sock" while php.ini says "pdo_mysql.default_socket=/var/mysql/mysql.sock". Should these be different like that? I tried making the php.ini setting empty to force it to default but that did nothing nor did changing it to "/tmp/mysql.sock".

Testing PDO outside Drupal seems to work for simple queries at least, testing this works just fins and returns the expected results:

<?php$pdo_connection = new PDO( 'mysql:host=localhost; dbname=imageboard', 'websqluser', 's=o_eP4SSw0rd');$query = "SELECT count(tagrelations.imageid) as count from tagrelations group by tagrelations.tagid order by count asc";$result = $pdo_connection->query($query) or die("Error: No db connection?");?>

@lostchord, not sure about that. From the looks of the OP's comment it appears Drupal will not allow him to install at all. So it is detecting the error in configuration and not allowing him to proceed.

The only reason I mention that it's probably not critical was that it sounds more like a local machine configuration problem then a Drupal core showstopper or else the entire community would have posted to this issue.

@NiklasBr
For curiousity's sake, can you successfull install an older version from before Alpha?

@webkenny, detection in this case is analgaous to "I detected the brick wall by running into it". This is exactly what appears to have happened, it hit the wall, hard, and is now sitting on the ground talking nonsense..."Are you sure you have the correct username and password?"

I think of these sorts of errors as critical because they prevent the application from being used. A potential user may give up and go try Joomla, or Wordpress, or.... That's not a good result! If this were a commercial application you would have lost a sale.

Installation is part of the core (or at least it should be considered as such!) so this has to be considered a core showstopper...the show never even got on the road!

I rolled back to a 7.x-dev install I did dec 12 (or about that date), cleared out the database and it installs fine, none of the alpha releases installs though. Today's 7.x-dev release does not install either.

Edit: Since alpha-1 does not work anymore (I think I remember it working) perhaps it is some sort of configuration error. Odd thing though is I consider my system and web server kosher in the sense that I only ever change as little as possible and then I only edit ini/conf files. The httpd.conf and php.ini files are the only files that I have edited unless my memory is failing me.

Another test I'd like you to run because I've seen something like this before in another area (Drush) is this. Assuming that your $db_url is set to "localhost" can you change that value to the IP address and install again? e.g. $db_url = user:password@127.0.0.1:3306/mydatabase

I noticed that in the PHP info you provided, mysql and mysqli have no value for default socket and I am wondering if that might be a root cause. Doesn't explain why this one is failing and the others didn't but maybe it will point us to the right place.

On OS X 10.6, after copying /private/etc/php.ini.default to /private/etc/php.ini, I saw the same error messages as in the OP. I commented out:

;pdo_mysql.default_socket=/var/mysql/mysql.sock

And I got rid of the errors. I believe this is because the actual MySQL socket does not match the one in the php.ini, as in #5 above. #5 above could have probably solved his problem by commenting out the line, instead of setting it to an empty string. I've tried setting it to the empty string, too, and it has no effect.

OS X ships with PHP, and by default it has no php.ini. If you copy /private/etc/php.ini.default to /private/etc/php.ini, you will inherit a misconfigured pdo_mysql.default_socket variable.

So, yes, this is a misconfiguration. I don't imagine it is Drupal's responsibility to correct misconfigurations, and anyway, you can't unset a php variable with php_value, which is what would be needed in this case.

The mysql.default_socket and mysqli.default_socket should be irrelevant to Drupal 7, as Drupal 7 and later only uses PDO for all DB connections. Probably not a bad idea to fix those too, but not relevant to Drupal.

Also dropping to normal, since this is just a documentation issue and apparently it's not causing widespread issues.

just to add some extra feedback of a different user: I had the same problem, yet over here it was solved merely by changing the 'host' => 'localhost' in my settings.php to 'host' => '127.0.0.1' for my local server.

I don't understand, since localhost is just an alias for 127.0.0.1, but I had this same issue and this fixed it for me as well. In our case, the site was built and was running php 5.3 and migrated to a server running php 5.5. Was getting the PDOException: SQLSTATE[HY000] [2002] No such file or directory in lock_may_be_available() error, changed from localhost to 127.0.0.1 in settings.php as mentioned above and voila!