Can't connect to local MySQL server through socket '/tmp/mysql.sock' error

bcobin - October 18, 2007 - 03:33

Mac OS X 10.4.10
PHP 5.2.1
MySQL 5.1

I've been working on my localhost with Drupal 5.1 successfully; I get the above error message during the installation process on Drupal 6 beta. The MySQL socket on my local server (which is working fine) is '/var/mysql/mysql.sock'; the installation is looking for '/tmp/mysql.sock' and fails, generating the Can't connect to local MySQL server through socket '/tmp/mysql.sock' error message.

I've moved the 5.1 Drupal files to a different folder for the Drupal 6 installation; when I move them back, everything works fine, so it's not the server instance.

I've tried adding the following line to the default.settings.php file in the "PHP Settings" section (this is from another post; I am not a coder):

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

to no avail.

It took me forever to originally get the local server working (frankly, I don't know how I did it) and I doubt I could even go back and mess with the system files. Is there a way to modify any of the installation files to properly point to my server instance, like 5.1 does? Thank you any and all for your help and patience - all you guys are so far beyond me it's not funny.

-billy

bcobin - at - icrmedia.com

Workaround

bcobin - October 18, 2007 - 03:40

From stephanejais:

June 8, 2007 - 17:22

Instead of connecting through your socket, you can replace localhost by 127.0.0.1 in the "Host" field of the advanced options.
This worked for me.

And for me, too. This should probably be addressed in the installation, though.

I have the same problem with

martig - February 15, 2008 - 13:52

I have the same problem with drupal 6. I have to use a socket other than the default, cause the default socket is reserved for other purposes. In drupal 5 adding that line to settings.php worked, but it's not working in drupal 6.

Does anyone have an idea how to solve this problem?
[edit]
I got it working by writing the hostname as localhost:/path/to/socket.sock

Same thing

Ninja Overlord - April 20, 2008 - 20:14

I'm trying to set up a multisite using Drupal 6.2, and I am getting this same error.

After including

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

I get the same thing. When I tried to put information into the settings.php file by hand, I got a bunch of errors saying tables did not exist, so I can't easily skip the installer via that method.

When I try to include the second solution mentioned above, the same screen ("Site-Offline") but with a different error:

Incorrect database name 'path/to/socket.sock/{my actual database name}'.

try adding a symlink for the socket file

omniverse - May 27, 2008 - 21:57

I got the same "socket /tmp/mysql.sock" error, so I created a symlink at /tmp/mysql.sock to my actual socket path. I am using a MAMP (Mac OS), but it should work on Linux as well.

from the command line:
ln -s /Applications/MAMP/tmp/mysql.sock /tmp/mysql.sock

Where is the mysql.sock?

Ninja Overlord - May 30, 2008 - 18:13

I cannot use that method of solving this because I have no idea where to make the symlink point to. And would that make the default install I have running broken? There simply is no /tmp directory at all, thus I have no idea where to have the symlink point to.

Until this is fixed, as far as I'm concerned, the 6.x install of Drupal does not work.

What I'm most confused about is that I have a regular install of Drupal set up already (in the default directory), and this came up when I tried to install a second site on the same codebase. Why wouldn't it work? I'm thinking of starting the whole Drupal install again with the release of 6.3, and ideally this won't be an issue anymore, a lot of the features I'd made use of on this site in 5.x are bugs that will be fixed in 6.3 anyway.

I've started a separate topic about this to lessen hijacking. See http://drupal.org/node/251784.

just find where your msyql.sock file actually lives

omniverse - July 17, 2008 - 04:10

The idea is to create a symlink at the spot Drupal is looking to point to your actual mysql.sock file.
ln -s /actual/path/mysql.sock /where/drupal/thinks/it/is/mysql.sock

Cannot Locate socket

cynicrp - July 17, 2008 - 11:57

I haven't a clue where my mysql.sock file lives. I have looked in all the possible directories on the server... nothing. I know it's running SQL, just cannot find it. This is causing the same error to come up in the drupal install.

| rep |

try changing the drupal

kenshi - January 23, 2009 - 00:13

try changing the drupal filesystem tmp path but just be mindful of other modules that may depend on this too.

Drupal Filesystem tmp path

cgroberts - March 18, 2009 - 08:04

Hi,

Which file do I need to edit for this tmp parameter

Thanks

Chris

drupal install on OS 10.5

jcrispin - March 18, 2009 - 03:19

Thanks! I was beating my brains in for hours an this worked! Good karma...

Try mysqli options

dougal - April 10, 2009 - 21:10

On my Mac OS X 10.5 system, it was actually trying to use the mysqli extension intead of the old mysql.

I fixed this problem by editing /etc/php.ini and setting:
mysqli.default_socket = /tmp/mysql.sock

Then I restarted apache (apachectl restart), and the rest of the install finished up just fine.

Unable to use 'localhost' when opening mysql on Mac OS X 10.5

dave261 - May 8, 2009 - 03:43

I've have been having this problem for some time. I could connect using the IP address and I could connect using dave.local. When I tried to connect using 'localhost' I got a 2002 error.

The fix turned out to be simple. I created a link to the actual mysql.sock that was in /tmp as follows:
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

The MySql 2002 error message will identify the socket it failed to open. In my case it was /var/mysql/mysql.sock

Make sure the /var/mysql directory exist prior to executing the above. If missing use sudo mkdir /var/mysql

Happy coding.

 
 

Drupal is a registered trademark of Dries Buytaert.