Entry
Why do I get the php error: MySQL Connection Failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' "111" when using mysql_connect()?
Dec 11th, 2002 14:07
Peter Bailey, John Crawford,
If you have done recent upgrades to your mysql, you may find that the
default socket entries in your my.cnf file (typically found
in /etc/my.cnf) specify that the socket for the server and client is
actually set to /tmp/mysql.sock.
For instance, recent PHP (I've just installed 4.3RC2) and MySQL (I've
just installed 4.0.5) end up with a configuration of the socket
as /var/lib/mysql/mysql.sock. Thus the two conflict, and PHP can't
connect to MySQL because it doesn't recognise the socket. You can fix
this by stopping your mysql server, and editing the /etc/my.cnf file
to specify /var/lib/mysql/mysql.sock as the socket setting for the
client and server. Then start the mysql daemon, and restart your web
server just to be safe. This solved my problems.
Alternatively, try the solution provided below if that seems to be
affecting you.
if you have a valid lock in
'/var/lib/mysql/mysql.sock'
and you can connect with mysql client
funkyfirewall:# mysql -u mywebapp -p goodness&light
but php can't and ... if you are using a machine with 2 NICs then try
setting the IP mysqld uses.
funkyfirewall:# mysqld -u mysql --bind-address=same.as.apache.ip &
then in your php use
$link = mysql_connect
("same.as.apache.ip", "mywebapp", "goodnes&light");
of course "same.as.apache.ip" is the ip you have apache bound to.
(??? try the external one)