PHP - MySQL连接不工作:2002没有这样的文件或目录 [英] PHP - MySQL connection not working: 2002 No such file or directory
问题描述
我要设置WordPress。我有Apache和MySQL运行,帐户和数据库都设置好了。我试着做一个简单的连接:
I'm trying to set up WordPress. I have Apache and MySQL running, and the accounts and database are all set up. I tried to make a simple connection:
<?php
$conn = mysql_connect('localhost', 'USER', 'PASSWORD');
if(!$conn) {
echo 'Error: ' . mysql_errno() . ' - ' . mysql_error();
}
?>
我总是得到这个:
错误:2002 - 没有此类文件或
目录
Error: 2002 - No such file or directory
谈论?
我在OS X Snow Leopard上,使用内置的Apache。我使用x86_64 dmg安装了MySQL。
I'm on a OS X Snow Leopard, using the built-in Apache. I installed MySQL using the x86_64 dmg.
更新:我发现套接字在/tmp/mysql.sock,所以在php.ini中,我替换了所有出现的错误的路径。
UPDATE: I found that the socket is at /tmp/mysql.sock, so In php.ini, I replaced all occurrences of the wrong path with that.
推荐答案
如果你使用Linux:mysql.sock文件的路径是错误的。这通常是因为您使用的是(LAMPP)XAMPP,而不是在/tmp/mysql.sock
If you use Linux: the path to the mysql.sock file is wrong. This is usually because you are using (LAMPP) XAMPP and it isn't in /tmp/mysql.sock
打开php.ini文件,找到这行: / p>
Open the php.ini file and find this line:
mysql.default_socket
并使它
mysql.default_socket = /path/to/mysql.sock
这篇关于PHP - MySQL连接不工作:2002没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!