I'm trying to set up WordPress. I have Apache and MySQL running, and the accounts and database are all set up. 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 could it be talking about?
I'm on a OS X Snow Leopard, using the built-in Apache. I installed MySQL using the x86_64 dmg.
UPDATE: I found that the socket is at /tmp/mysql.sock, so In php.ini, I replaced all occurrences of the wrong path with that.
The error 2002 means that MySQL can't connect to local database server through the socket file (e.g. /tmp/mysql. sock ). then double check that your application uses the right Unix socket file or connect through the TCP/IP port instead. and make sure that file exists.
normally means that there is no MySQL server running on the system or that you are using an incorrect Unix socket file name or TCP/IP port number when trying to connect to the server. You should also check that the TCP/IP port you are using has not been blocked by a firewall or port blocking service.
The error above commonly happens when you run a long or complex MySQL query that runs for more than a few seconds. To fix the error, you may need to change the timeout-related global settings in your MySQL database server.
I had a similar problem and was able to solve it by addressing my mysql with 127.0.0.1
instead of localhost
.
This probably means I've got something wrong in my hosts setup, but this quick fix get's me going for right now.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With