Mac OS Snow Leopard: Why does my mysql.default_socket value not change in my phpinfo() page?

18,324

Solution 1

PHP should be looking for a php.ini file (and not php.ini.default) to load, so try renaming php.ini.default to php.ini. See Install Apache/PHP/MySQL on Snow Leopard.

Solution 2

If you don't want to muck about with config settings for either mysql or php, then set up this hack:

mkdir /var/mysql

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

This creates an alias in the location that PHP is looking for that connects to the real mysql.sock.

Solution 3

Bring the mysql.sock to PHP

One problem that has come about with MySQL and Leopard is the location of the mysql.sock file. Previously, the default location for this file was in the /tmp directory. That location has now moved to the /var/mysql directory. PHP will look for it there. Unfortunately, the default location from the MySQL will still place it in the old location. We can fix this by creating a my.cnf configuration file in the /etc directory. Save a file with the following contents to /etc/my.cnf:

[client] socket = /var/mysql/mysql.sock

[mysqld] socket = /var/mysql/mysql.sock

In the terminal window, type the following commands to create the directory for the sock file:

sudo mkdir /var/mysql sudo chown _mysql /var/mysql

Source: http://www.procata.com/blog/archives/2007/10/28/working-with-php-5-in-mac-os-x-105/

Solution 4

Simply creating the /etc/my.cnf file with contents and creating the directory, per Vikash's recommendation, did not solve the problem. mysql.sock still was living in /tmp, even after doing this and restarting the machine. I manually moved the file from /tmp to /var/mysql, and then the error resolved. I had a feeling, though, that upon restart the problem would resurface, and it did. This time the error was slightly different - connection denied. I found that a new socket had been opened in /tmp and the old one was still there in /var/mysql; the code was trying to use the old one and getting denied access. So I used Sid's hack with the symlink and that fixed the problem. I'm sure when I restart, this fix will still work. However, I'd love to know what is causing the system to open new sockets in /tmp instead of the configured /var/mysql.

Solution 5

Try just doing a symlink. For my XAMPP installation this worked:

sudo ln -s /Applications/XAMPP/xamppfiles/var/mysql/ /var/mysql
Share:
18,324
Admin
Author by

Admin

Updated on September 17, 2022

Comments

  • Admin
    Admin almost 2 years

    I'm getting errors whenever I try to connect locally to mySQL on Mac OS Snow Leopard 10.6.4. I'm running mySQL 5.1.46. I can log in using the console. I'm running PHP 5.3.2 and my phpinfo() page is working fine. So I've got PHP running, I can log into the mySQL server using both the console and Sequel Pro.

    So I suspected that it was a socket issue. In my /etc directory, I don't have php.ini, I have php.ini.default. So I go in there, and every place I see "default_socket" I change it from:

    /var/mysql/mysql.sock
    

    to:

    /tmp/mysql.sock
    

    I see it in the following locations:

    pdo_mysql.default_socket=/tmp/mysql.sock
    mysql.default_socket = /tmp/mysql.sock
    mysqli.default_socket = /tmp/mysql.sock
    

    And when I go to connect to phpMyAdmin, I get the following error: Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly.

    And when I look in my phpinfo() file, I get the following under mySQL:

    mysql.default_socket /var/mysql/mysql.sock /var/mysql/mysql.sock
    

    I restart Apache... heck, I restart the whole computer. Still, nothing. I know mySQL is working, I know PHP is working, but I can't get them talking.

    Any help?

  • John Doe
    John Doe almost 14 years
    Lekensteyn, I created a page named "test.php" and pasted your code with the appropriate un/pw and got this error: Warning: mysql_connect() [function.mysql-connect]: [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /Library/WebServer/Documents/test.php on line 3 Warning: mysql_connect() [function.mysql-connect]: No such file or directory in /Library/WebServer/Documents/test.php on line 3 No such file or directory
  • Admin
    Admin almost 14 years
    This was the one that fixed it. Then I read Vikash's answer to see why. Thanks so much!
  • Brinda K
    Brinda K almost 14 years
    Thank you so much for the awesome answer. Renaming the php.ini.default file worked, but I understand it much better thanks to this response.
  • Justin
    Justin over 9 years
    Awesome. Works and you don't even have to restart anything!