views:

835

answers:

4

I tried to use WordPress, and it would never work. I have apache and mysql running, the accounts and database are all set up, there are no typos. So I tried to make a simple connection:

<?php
    $conn = mysql_connect('localhost', 'USER', 'PASSWORD');
    if(!$conn) {
        echo 'Error: ' . mysql_errno() . ' - ' . mysql_error();
    }
?>

And I always get this:

Error: 2002 - No such file or directory

What file or directory?? Any idea what might be causing this? Thanks.

Also, I'm on a mac, Snow Leopard, with built in apache and the x86_64 dmg installer of MySQL.

UPDATE: Ok, I found that the socket is at /tmp/mysql.sock, so In php.ini, I replaced all occurrences of the wrong path with that. I'll see if it works now.

+3  A: 

I'd check your php.ini file and verify the mysql.default_socket is set correctly and also verify that your mysqld is correctly configured with a socket file it can access. Typical default is "/tmp/mysql.sock".

Myles
Ok, It says `/var/mysql/mysql.sock`, but that path doesn't exist.
Mk12
+2  A: 

Not that it helps you much, but in the recent versions (and even less recent) of MySQL, error code 2002 means “Can't connect to local MySQL server through socket [name-of-socket]”, so that might tell you a bit more.

Arthur Reutenauer
+3  A: 

First, ensure MySQL is running. Command: mysqld start

If you still cannot connect then: What does your /etc/my.cnf look like?

The other 2 posts are correct in that you need to check your socket because 2002 is a socket error.

A great tutorial on setting up LAMP is: http://library.linode.com/lamp-guides/centos-5.3/index-print

Todd Moses
The installer didn't put a my.cnf file, however there is a `/usr/local/mysql/mysql-test/include/default_my.cnf`, should I copy that as my.cnf to `/etc` ?
Mk12
yes, but you may find that you need to modify it some latter.
Todd Moses
+5  A: 

If you use Linux: the path to the mysql.sock file is wrong. This is usually because you are using (LAMPP) XAMPP and it isn't in /tmp/mysql.sock

Open the php.ini file and find this line:

mysql.default_socket

And make it

mysql.default_socket = /path/to/mysql.sock
Ramblingwood
if you're not sure , try /var/lib/mysql/mysql.sock as the new path to the socket.
Jay
WordPress works now! I actually remember going through a tutorial saying to do this, but read somewhere that you don't need to on Snow Leopard or something like that.
Mk12
Hmm. Maybe they meant Leopard or Tiger. In any case, have fun with WordPress!
Ramblingwood