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.
Restarting the mysql server might help. In my case, restarting the server saved a lot of time.
P.S.- use
sudo service mysql restart
for non-root user.Replacing 'localhost' to '127.0.0.1' in config file (db connection) helped!
I had a similar problem and was able to solve it by addressing my mysql with
127.0.0.1
instead oflocalhost
.This probably means I've got something wrong in my hosts setup, but this quick fix get's me going for right now.
I encountered this problem too, then i modified 'localhost' to '127.0.0.1',it works.
I've installed MySQL using installer. In fact, there was no data directory alongside 'bin' directory.
So, I manually created the 'data' directory under "C:\Program Files\MySQL\MySQL Server 8.0". And it worked (changing the root password following steps suggested on https://dev.mysql.com/doc/mysql-windows-excerpt/5.7/en/resetting-permissions-windows.html.
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