Drupal tries to access database using wrong mysql.sock

Status: 
Solved
Question: 

I'm trying a first install of Drupal-6.10 on Mac OS X 10.5.6. I have set up a mysql datbase for it an can access it properly from the command line, but when I try to go through the installation pages of Drupal according to the book, when it comes to accessing the database, I get the message: "Failed to connect to your MySQL database server. MySQL reports the following message: Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)."
The problem is that mysql.sock is at /tmp/mysql.sock. I've looked through everything in the drupal-6.10 directory and can find no reference to mysql.sock. How can I tell drupal to look in the correct place?

Responses

1. This is usually a problem

This is usually a problem with your mysql installation. I remember struggling with a similar error on my slackware computer. Mysql.sock is a file that is created upon the startup of your sql server (if I remember correctly). You might find more assistance on a mac - sql forum, since this is not drupal specific.

Good luck.

2. To change MySQL or Drupal setting?

Thanks. I had considered that, but then I figured that since all mac programs that use mysql would presumably be looking for mysql.sock in the same place, whereas Drupal "knows" it is somewhere else, there must be somewhere in Drupal where the location is set, and therefore where it could be reset to point to the mac-standard place. Are you saying that this is not true, and that any other mac program that assumes mysql.sock is in /tmp/mysql.sock should be fixed to look at /var/mysql/mysql.sock? Or are you saying that other programs using mysql (such as Ruby on Rails, which I also propose to try) will be looking at /var/mysql/mysql.sock, and that I should try reinstalling mysql?

3. I've scanned my drupal folder

I've scanned my drupal folder contents, and there is no place that it refers to mysql.sock, so you cannot change it anywhere.

You might find a solution here:

http://drupal.org/node/345884

4. Interesting link

Thanks very much for that pointer, which suggests that the problem does not belong to Drupal or to MySQL, but is in PHP. One must fix php.ini.

It may be interesting, to someone following this thread to find a solution to the same problem, that there is still a question. One writer claims to have solved it by editing php.ini to set the right socket location, whereas two following writers were unable to duplicate that success.

I finally solved it from a comment at the foot of this link:

The answer is to create a symbolic link from /tmp/mysql.sock to /var/mysql/mysql.sock

sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

Now I have a functioning local Drupal installation.

----------------------

There seems to be something funny about the page , and I wonder if this says something about Drupal code? When I first accessed it using Firefox 3.0.8 on an Intel Mac OS X 10.5.6, Firefox crashed after a short wait. So I tried Safari 3.2.1, which has a different engine. It crashed immediately. I tried Firefox again, and it showed the page without crashing, but with no content in the various boxes. I tried on a PPC Mac. Firefox 3.0.8 crashed the first time I went to the page, but after I restarted the PPC Firefox 3.0.8, it quite happily read the page with all content. Several further tries at reloading (cache cleared) it with Firefox 3.0.8 on the Intel Mac give the same set of box frames but no content.

5. Clarification

At the head of my message I wrote that one needed to edit php.ini. I wrote that before finding the effective fix -- the symbolic link. One does not have to mess with php.ini at all.