I am attempting to connect with my MySQL DB using the Terminal on my small Apple (With PHP).

Yesterday it labored fine, and today I all of a sudden understand this error (See title). I have no idea how you can solve it. I have spend my spare time trying today =(

The script works after i use my Browser to operate it (I've XAMPP installed), but Terminal will not connect with the DB.

Her eis the file which i include for connecting (Script works after i don't include this however it does not connect with the DB):

    mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("FNB1C_data") or die(mysql_error());

That needs to be right owing to my Browser I'm able to connect after i run the script.

The command I personally use is "php scriptname.php".

For whatever reason mysql on OS X will get the locations from the needed socket file a little wrong, but because of a veritable wizard I understand (that's you, Gavin) the answer is actually establishing a symbolic link.

You might have a socket (showing up like a zero length file) as /tmp/mysql.sock or /var/mysql/mysql.sock but 1 or even more applications is searching within the other location for this.

Instead of slowly move the socket and also have to edit config files and don't forget to help keep edited files local and from servers in which the pathways are correct, simply produce a symbolic link so that your mac finds the needed socket, even if it's searching within the wrong place!

For those who have /tmp/mysql.sock but no /var/mysql/mysql.sock then...

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

For those who have /var/mysql/mysql.sock but no /tmp/mysql.sock then

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

You'll need permissions to produce your directory and link, so just prefix the instructions above with sudo if required.

Hope this can help. It's sorted this exact problem for me personally on 3 apple computers to date.

Hei take a look here link text

Problem #2: PHP tossing error "Warning: mysql_connect() http://function.mysql-connect: 2002 No such file or directory (attempting to connect via unix:///tmp/mysql.sock)"

Treatment For Problem #2: Set "mysql.default_socket" value inside your /etc/php.ini to "mysql.default_socket = /var/mysql/mysql.sock". Then restart web service in server admin

I additionally had this error, but tend to only repair it with the suggestion here.

In summary, use:

Rather than:


This is because "localhost" is really a special reputation for the mysql driver which makes it make use of the unix socket for connecting to mysql rather than the a tcp socket.