mysql.sock problem--please help!

twoblackeyes - January 25, 2006 - 07:33

I am getting the dreaded error when accessing http://localhost/drupal:
Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) in /Library/WebServer/Documents/drupal/includes/database.mysql.inc on line 31
Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)

Here's the info:

I'm installing on OS X 10.4, drupal 4.6.5, mysql 5 (I've also tried with mysql 4.1, same problem).

The weird thing is, I had drupal running just fine off of my local machine (all I want to do) a month ago, and it mysteriously stopped working and all I can get is that error. My settings.php file is setup correctly, I'm sure. I am able to access the drupal database in mysql with the drupal user using MySQL Query Browser, so I know the mysql server is running fine (mysqld running). Strangely enough, I get the same error whether the mysql server is running or not.

I've read every forum topic on this tonight, and no solutions seemed to help. I got excited when I discovered there is no directory /var/mysql/ on my machine--my mysql.sock appears to be located in /tmp -- I tried creating a symbolic link as someone else had suggested to no avail. I feel like this might be where the problem lies though. Is there any way I can tell drupal to not look in /var/mysql and to look in /tmp for mysql.sock aside from the symbolic link?

The annoying thing is, drupal is running just fine on my site5 webserver. I just want to run it locally on my own machine so I can develop my site's theme without having to load things onto the server.

Any help from anyone would be so excellent, I am going insane.

this is mysql client issue, so....

paddy_deburca - January 26, 2006 - 10:47

Can you update your mysql configfile (my.cfg) as in http://dev.mysql.com/doc/refman/4.1/en/problems-with-mysql-sock.html.

This shows where the server puts the socket file and where the client should go to find it.

Goof Luck,

Paddy.

http://deburca.org, and http://amadain.net

The version of PHP that

frjo - January 25, 2006 - 15:14

The version of PHP that Apple included with Mac OS X 10.4.4 has mysql.default_socket set to "/var/mysql/mysql.sock", before it was "/tmp/mysql.sock". They change it for some security reasons I believe.

The binary version of MySQL from mysql.com use "/tmp/mysql.sock" so one has to change.

I choose to make PHP look for "/tmp/mysql.sock" by setting this in /etc/php.ini.

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
mysql.default_socket = /tmp/mysql.sock

I also tried to go the other way by setting this in /etc/my.cnf.

#Name of the socket file to use.
socket=/var/mysql/mysql.sock

Both work but I went with the first solution because the second one made the MySQL preference pane stop working.

thanks

twoblackeyes - January 26, 2006 - 05:39

thank you both for replying--I will try all of these fixes tomorrow when I have access to my home machine--hopefully one of them will work

hmm

twoblackeyes - January 26, 2006 - 19:30

frjo,

I tried your first change and it didn't seem to work. Although there was a condition--I only have php.ini.default in /etc not php.ini, although I tried editing the .default version with the change, as well as renaming it php.ini with the change, and neither worked.

Mysteriously enough, I also don't have any file called my.cnf in /etc, not even a .default version. Could this be the problem?

You need to create the file(s)

frjo - January 27, 2006 - 08:44

You need to create the file(s) "/etc/php.ini" and/or "/etc/my.cnf" yourself.

When MySQL and PHP don't find any settings files they simply use the default values.

"php.ini.default" is a example php.ini file, you can make a copy of it and rename it to "php.ini" if you like.

Remember to read the comment at the top of "php.ini.default" first!

If you bare with me, I will check this evening

paddy_deburca - January 27, 2006 - 10:23

I have Mac OSX, mySQL and drupal running at home. If you bare with me I will gather all the information I can find and include it in a post.

How is your mySQL started ? as a deamon?

Can you look in /Library/StartupItems/{something-like-mysql} and have a look at the start-up script. It may give you the location of the .cnf files to look for and may also point you to the location of a default version.

Paddy.

http://deburca.org, and http://amadain.net

I'm starting up mysql via

twoblackeyes - January 28, 2006 - 00:38

I'm starting up mysql via the mysql prefpane. When I look at activity monitor, it says mysqld is up and running fine.

I don't have mysql coming on at startup, so there's nothing in that folder currently.

If I'm going to create a my.cnf file, what do I put in it? Can I just put that one line about the socket, and then assume the rest will go to defaults?

Any help you have about your system would be great. I can't believe this still isn't working, when it used to work on my computer just fine.

Thanks

Well, as these things often

twoblackeyes - January 28, 2006 - 01:31

Well, as these things often do with me, it came down to stupidity.

After editing php.ini with the change frjo mentioned, I was restarting mysql and not apache before trying again. Restarting apache seemed to do it.

I also changed the priveleges of /tmp so www could read it by doing this at the terminal, so that might have helped too:

sudo chmod 775 /tmp

There is extensive confusion on this topic (upgrades to 10.4.4 mucked around with the mysql.sock location, it seems) and here are some links from apple and others:

http://docs.info.apple.com/article.html?artnum=301457
http://docs.info.apple.com/article.html?artnum=302977
http://www.afp548.com/article.php?story=20051204002042215
http://forums.mysql.com/read.php?20,37144,66425#msg-66425

Thanks so much to everyone for helping. Really.

I am a little bit confused..

paddy_deburca - January 28, 2006 - 16:42

On my system, /tmp is a symbolic link to /private/tmp, and /private/tmp has a permission of

drwxrwxrwt .... root  wheel  .... Jan 28 17:28 /private/tmp

Now the 't' at the end signifies a sticky bit man 8 sticky gives

A directory whose `sticky bit' is set becomes an append-only directory,
or, more accurately, a directory in which the deletion of files is
restricted.  A file in a sticky directory may only be removed or renamed
by a user if the user has write permission for the directory and the user
is the owner of the file, the owner of the directory, or the super-user.
This feature is usefully applied to directories such as /tmp which must
be publicly writable but should deny users the license to arbitrarily
delete or rename each others' files.

I think that a

chmod 1777 /private/tmp

is more correct.

Paddy.

http://deburca.org, and http://amadain.net

Thank-you

Amazon - January 28, 2006 - 04:32

Grrrrr.

I have been wondering what stupid thing I did to break my mac for the last week or so. I have been looking for answers everywhere. Thrilled to find the answer right under my nose.

Development manager CivicSpace Labs

 
 

Drupal is a registered trademark of Dries Buytaert.