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

Comments

bcobin’s picture

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.

martig’s picture

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

tnanek’s picture

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}'.

omniverse’s picture

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

tnanek’s picture

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.

omniverse’s picture

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

cynicrp’s picture

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 |

kaicong’s picture

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

cgroberts’s picture

Hi,

Which file do I need to edit for this tmp parameter

Thanks

Chris

jcrispin’s picture

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

dougal’s picture

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.

dave261’s picture

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.

magicg’s picture

Here is a Tip:
Easy Troubleshooting

jessekanner’s picture

I've had another variation on the problem discussed above - only I'm running MAMP on a Mac, which has it's own little environment under its own folder inside the Applications directory. Although Apache/PHP was able to make connections fine, the mysql CLI client kept showing connection errors.

Here's the MAMP version of soft linking the mysql.sock file outside of MAMP world and out into the filesystem/OS at large (where the mysql CLI expects it):

cd /tmp
sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock mysql.sock

kris-o3’s picture

i've intermittently had the same issue on various versions of os x (in my case 10.6 server)

my solution...

  • edit /etc/my.cnf
  • change references for mysql.sock to /tmp/mysql.sock
  • edit /System/Library/LaunchDaemons/org.mysql.mysqld.plist
  • change --socket=??? to --socket=/tmp/mysql.sock
  • reboot

this should resolve 'both ends' of where mysqld/pdo is attempting to 'locate' mysql.sock