I have a problem when i run my php code (sometimes it runs successfully, but I need how to avoid it in future) the error appears as :
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
and "/home/myegyme/public_html/Connections/myegy.php" contains :
<?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,开发者_JS百科 $password_myegy) or trigger_error(mysql_error(),E_USER_ERROR);
?>
How can I solve this problem?. please help me !
add
[client]
socket=/var/lib/mysql/mysql.sock
to my.cnf
as described on
http://www.tech-recipes.com/rx/762/solve-cant-connect-to-local-mysql-server-through-socket-tmpmysqlsock/
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.
Change the word "localhost" to "127.0.0.1" and your mysql will no longer attempt to connect to the socket, but rather over TCP/IP.
精彩评论