警告:mysql_connect():[2002]没有这样的文件或目录(试图通过unix:///tmp/mysql.sock连接) [英] Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///tmp/mysql.sock) in

查看:549
本文介绍了警告:mysql_connect():[2002]没有这样的文件或目录(试图通过unix:///tmp/mysql.sock连接)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试连接到我的MySQL数据库与终端在我的苹果(与PHP)。

I'm trying to connect to my MySQL DB with the Terminal on my Apple (With PHP).

昨天它工作正常,现在我突然得到这个错误(见标题)。我没有线索如何解决它。我花了所有的空闲时间尝试今天=(

Yesterday it worked fine, and now I suddenly get this error (See title). I have no clue how to solve it. I've spend all my free time trying today =(

脚本工作时,我使用我的浏览器运行它(我安装XAMPP),但拒绝连接到数据库。

The script works when I use my Browser to run it (I have XAMPP installed), but Terminal refuses to connect to the DB.

她是我包含的文件连接(脚本工作时,我不包括这个,但然后没有连接到数据库):

Her eis the file that I include to connect (Script works when I don't include this but then it doesn't connect to the DB):

<?php
    mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("FNB1C_data") or die(mysql_error());
?>

这应该是正确的,因为我的浏览器,我可以连接时,我运行脚本。

That should be right since with my Browser I can connect when I run the script.

我使用的命令是php scriptname.php 。

The command I use is "php scriptname.php".

推荐答案

由于某种原因,OS X上的mysql会得到所需套接字文件的位置有点错误,

For some reason mysql on OS X gets the locations of the required socket file a bit wrong, but thankfully the solution is as simple as setting up a symbolic link.

您可能有一个socket(显示为零长度文件)为/tmp/mysql.sock或/ var / mysql / mysql.sock,但1个或更多的应用程序正在寻找其他位置。

You may have a socket (appearing as a zero length file) as /tmp/mysql.sock or /var/mysql/mysql.sock but 1 or more apps is looking in the other location for it.

而不是移动套接字,并且必须编辑配置文件,并记得保持编辑文件本地并远离路径正确的服务器,只需创建一个符号链接,以便您的mac找到所需的套接字,即使它在错误的地方!

Rather than move the socket and have to edit config files and remember to keep edited files local and away from servers where the paths are correct, simply create a symbolic link so your mac finds the required socket, even when it's looking in the wrong place!

如果你有/tmp/mysql.sock,但没有/var/mysql/mysql.sock然后...

If you have /tmp/mysql.sock but no /var/mysql/mysql.sock then...

cd /var 
sudo mkdir mysql
sudo chmod 755 mysql
cd mysql
sudo ln -s /tmp/mysql.sock mysql.sock

如果您有/var/mysql/mysql.sock,但没有/tmp/mysql.sock,则

If you have /var/mysql/mysql.sock but no /tmp/mysql.sock then

cd /tmp
ln -s /var/mysql/mysql.sock mysql.sock

您需要具有创建目录和链接的权限,所以只要在上面的命令前面加上sudo即可。

You will need permissions to create the directory and link, so just prefix the commands above with sudo if necessary.

希望这有帮助。到目前为止,它已经排序这个确切的问题为我的3 macs。

Hope this helps. It has sorted this exact issue for me on 3 macs so far.

这篇关于警告:mysql_connect():[2002]没有这样的文件或目录(试图通过unix:///tmp/mysql.sock连接)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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