Web Hosting Talk







View Full Version : Help! MySQL Connection Problem (mysql.sock)


raylin
04-15-2001, 07:45 PM
I can manage MySQL thru phpMyAdmin, but can not connect to MySQL using the function on my php file:
mysql_connect ("localhost", $myid, $mypd);

The error message is :

Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111) in /home/sites/site1/web/dbcall.inc on line 10


I check /tmp/mysql.sock:

[root admin]# ls -l /tmp/my* /home/mysql/mysql.sock
srwxrwxrwx 1 mysql root 0 Apr 16 06:39 /home/mysql/mysql.sock
lrwxrwxrwx 1 root root 22 Apr 16 06:39 /tmp/mysql.sock -> /home/mysql/mysql.sock
[root admin]#

It seems OK. (I am not sure if the owner or group is fine)

Anyone gives me suggestions to fix this?

Thanks in advance.

-Edward-
04-16-2001, 04:36 AM
just restart mysql.

huck
04-16-2001, 09:30 AM
Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)

I had the same problem and it drove me crazy. I found a lot of simple solutions that never seemed to work.

My problem was with the my.cnf configuration file. Depending on how you installed MySQL, you should have a my.cnf file or equivalent in /etc. This file has a line for the mysqld that specifies the location of the mysql.sock file.

This line for some reason did not point to /tmp/mysql.sock but to another directory. I changed this line, made sure mysql.sock was in /tmp and restarted the mysqld. Problem solved.

Here's a snippet of the my.cnf file:

......
#The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
set-variable = key_buffer=16M
set-variable = max_allowed_packet=1M
......


Hope this helps.

raylin
04-16-2001, 06:12 PM
Technics and huck,

Thanks for your kindly help.

After 24 hr, I finally found the problem.

I made a BIG MISTAKE:blush:. I have 2 servers, ServerA with MySQL installed and ServerB not. I thought my site is on ServerA, but it is actually on ServerB.

So, it's nature that php files cannot find /tmp/mysql.sock to connect to MySQL on ServerB.

Sorry, it's my fault.