MySQL连接无法正常工作:2002没有这样的文件或目录 [英] MySQL connection not working: 2002 No such file or directory

查看:65
本文介绍了MySQL连接无法正常工作:2002没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置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?

我在使用内置Apache的OS X Snow Leopard.我使用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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆