Can't connect to local MySQL server through socket '/tmp/mysql.sock
The relevant section of the MySQL manual is here. I'd start by going through the debugging steps listed there.
Also, remember that localhost and 127.0.0.1 are not the same thing in this context:
- If host is set to
localhost
, then a socket or pipe is used. - If host is set to
127.0.0.1
, then the client is forced to use TCP/IP.
So, for example, you can check if your database is listening for TCP connections vi netstat -nlp
. It seems likely that it IS listening for TCP connections because you say that mysql -h 127.0.0.1
works just fine. To check if you can connect to your database via sockets, use mysql -h localhost
.
If none of this helps, then you probably need to post more details about your MySQL config, exactly how you're instantiating the connection, etc.