1

我在运行我的 php 代码时遇到问题(有时它运行成功,但我需要将来如何避免它)错误显示为:

PHP Fatal error:  Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/myegyme/public_html/Connections/myegy.php on line 9

/home/myegyme/public_html/Connections/myegy.php ”包含:

<?php
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_myegy = "localhost";
$database_myegy = "mydatabase";
$username_myegy = "myusername";
$password_myegy = "mypassword";
$myegy = mysql_pconnect($hostname_myegy, $username_myegy, $password_myegy) or trigger_error(mysql_error(),E_USER_ERROR); 
?>

我怎么解决这个问题?。请帮我 !

4

3 回答 3

1

添加

[client]
socket=/var/lib/mysql/mysql.sock

my.cnf如上所述_

http://www.tech-recipes.com/rx/762/solve-cant-connect-to-local-mysql-server-through-socket-tmpmysqlsock/

于 2011-01-07T16:18:17.133 回答
0

I had that problem once, when the socket was already in use (another program or database). Maybe that is the case, if you say that it runs sometimes.

于 2011-01-07T16:18:15.270 回答
-1

将单词“localhost”更改为“127.0.0.1”,您的 mysql 将不再尝试连接到套接字,而是通过 TCP/IP。

于 2011-01-07T16:23:20.070 回答