MySQL 连接不工作:2002 没有这样的文件或目录 [英] 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
它可能在谈论什么文件或目录?
What file or directory could it be talking about?
我在 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文件,找到这一行:
Open the php.ini file and find this line:
mysql.default_socket
并成功
mysql.default_socket = /path/to/mysql.sock
这篇关于MySQL 连接不工作:2002 没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!