Article:
  Apache Web-Serving With Mac OS X, Part 5
Subject:   mysql socket problem
Date:   2006-06-22 07:51:14
From:   carlco2
im getting the error


Warning: mysql_connect(): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) in /Library/WebServer/Documents/sqlaccess.php on line 5



Warning: mysql_select_db(): Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2) in /Library/WebServer/Documents/sqlaccess.php on line 9



Warning: mysql_select_db(): A link to the server could not be established in /Library/WebServer/Documents/sqlaccess.php on line 9


Can't connect to local MySQL server through socket '/var/mysql/mysql.sock' (2)


i can access mysql with cocoamysql and through phpmyadmin no problem i have mysql-standard-4.1.12-apple-darwin7.9.0-powerpc installed and aliased as mysql, tried sudo chown but still no joy accessing from apache webserver can someone shed some light? many thanks

Full Threads Oldest First

Showing messages 1 through 4 of 4.

  • mysql socket problem - solved differently
    2009-08-23 07:27:49  ekklisis [View]

    After spending a few hours on the console, without knowing much about how to use it, I realized that some of the links provided in the above article were not working in my ibook, because the installation path is different. So I decided to write a simple complement for those who might encounter the same problems.

    First of all, Mark Liyanage's double-clickable MySQL page sent me to the following link, which asked me to register.
    http://dev.mysql.com/get/Downloads/MySQL-4.1/mysql-standard-4.1.22-apple-darwin8.6.0-powerpc.dmg/from/pick

    Of course I didn't register, so I googled for a mirror of the file to be downloaded:
    mysql-standard-4.1.22-apple-darwin8.6.0-powerpc.dmg

    The particular package contains a startup item, which I also installed for restarting the MySQL server every time I restart my computer.

    After installation I was supposed to say hello to MySQL, as Kevin's article suggests, but I got the above-mentioned frustrating, yet stupid error.

    The solution:
    We open a command shell.
    we change dir to /private/etc with the command:

    cd /private/etc

    We copy the file php.ini.default to a writable directory in order to be able to edit it. (chmod did not work in my case). I used the commands:

    cd /

    sudo cp php.ini.default /private/etc/php.ini.default

    Then I opened it with the pico text editor:

    pico php.ini.default

    I hit ctrl+W to find mysql.default_socket =
    and I changed it to:
    mysql.default_socket = /private/temp/mysql.sock

    Ctrl+O to save
    and
    Ctrl+X to exit the editor.

    Then to put the file back in its place:

    sudo mv php.ini.default /private/etc/php.ini.default

    (Of course it asked whether I wanted to overwrite the old file and I said yes.) Unfortunately I don't remember whether it needs a chmod +w so, you'll have to figure it out yourself.

    Then I followed the advice of our fellow user carlco2 posted at his comment "Mysql socket problem solved.. OSX10.4 2006-06-23 04:59:13"

    sudo mkdir /var/mysql

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

    I then restarted and wow! MySQL server did not only start automatically, but also php and MySQL could meet each other, enabling me to finally run Kevin's "test.php" and excitedly say hello to MySQL ;)

    I will be happy if my blah blah becomes of some help to someone.
    Thanks for reading!
  • mysql socket problem solved.. OSX10.4
    2006-06-23 04:59:13  carlco2 [View]

    After updating to Mac OS X 10.4.4, you may find that the connection between PHP and MySQL running on your local webserver is broken.

    Apparently the socket file got moved in the update. You can make it start working again by entering the following commands in a Terminal window:

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

    http://www.macosxhints.com/article.php?story=20060111113313511
    • ignore last entry!
      2006-06-23 05:35:31  carlco2 [View]

      The reason you must not use /tmp/mysql.sock is that any Tom, Dick or Other can simply delete it and bring your php-mysql system down.

      The fix is actually simple:
      sudo mkdir -p /var/mysql
      sudo chgrp mysql /var/mysql
      sudo chmog g+w /var/mysql

      edit/create /private/etc/my.cnf and add the line:
      socket=/var/mysql/mysql.sock

      restart mysql

      now the new php wil find the socket info in the right place, if you change php then you might need to tell that about the new secure location.
      http://www.macosxhints.com/article.php?story=20060111113313511
      • ignore last entry!
        2007-01-23 19:42:33  bobga [View]

        in the my.cnf (mine is in /etc/my.cnf) file you need two sections to contain the socket directive

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

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

        Without both of them you are pointing to different sockets (with the server (mysql) mysqld and the client (client) mysql and mysqladmin apps)

        It may be better just to copy one of the sample cnf files from /usr/local/mysql/support-files. Copy one of the samples (i used my-small.cnf as it's just for my home web server) to /etc/my.cnf and edit as needed (i.e. change /tmp/mysql.sock to /var/mysql/mysql.sock)

        Good luck,
        s-