mysql server connection error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dickey
Forum Commoner
Posts: 50
Joined: Thu May 16, 2002 8:04 pm
Location: Sydney, Australia

mysql server connection error

Post by dickey »

Using script under unix:
mysql_connect("localhost", "user", "user_password")or die("server connection error");
mysql_select_db("bt") or die("database connection error");

Returns error message:
Warning: MySQL Connection Failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)
Server connection error

PHP seems to be functioning well.

Checked php.ini, nothing stands out as an issue.

Code: Select all

mysql.allow_persistent = On
mysql.max_persistent	 = -1
mysql.max_links = -1
mysql.default_port =
mysql.default_host =
mysql.default_user =
mysql.default_password =

Any assistance will be appreciated.

-Andrew
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

http://php.net/mysql_connect
Note: Whenever you specify "localhost" or "localhost:port" as server, the MySQL client library will override this and try to connect to a local socket (named pipe on Windows). If you want to use TCP/IP, use "127.0.0.1" instead of "localhost". If the MySQL client library tries to connect to the wrong local socket, you should set the correct path as mysql.default_host in your PHP configuration and leave the server field blank.
The socket-path configuration stands in my.cnf (at least it should ;) )
dickey
Forum Commoner
Posts: 50
Joined: Thu May 16, 2002 8:04 pm
Location: Sydney, Australia

Thanks Volka

Post by dickey »

Changing the script to 127.0.0.1:3306 etc works.

I haven't ever needed to specify it in that way before.

Thanks again.
Post Reply