错误 #2002 无法通过 socket '/Applications/MAMP/tmp/mysql/mysql.sock' 连接到本地 MySQL 服务器 (2)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11105796/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:53:10  来源:igfitidea点击:

Error #2002 Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2)

mysqlmampmysql-error-2002

提问by Brandon Beeler

I'm running MAMP.
It has been working fine up until yesterday. I haven't been able to find anything that helps so far. But here is my problem:

我正在运行 MAMP。
直到昨天它一直工作正常。到目前为止,我还没有找到任何有帮助的东西。但这是我的问题:

As the title states I'm receiving the following error:

正如标题所述,我收到以下错误:

error #2002 "Can't connect to local MySQL server through socket '/Applications/MAMP/tmp/mysql/mysql.sock' (2)"

错误#2002 “无法通过套接字'/Applications/MAMP/tmp/mysql/mysql.sock'(2)连接到本地MySQL服务器”

which, I have noticed, seems to be a pretty common error when I search for it.

我注意到,当我搜索它时,这似乎是一个非常常见的错误。

Anyway, When I cd to tmp/mysqland ls -laxothe only thing that shows up besides the ./and ../directories is .dummy(I have no idea what that is, but I have a hunch it's not the source of my problem).

无论如何,当我 cd 到时tmp/mysqlls -laxo除了./../目录之外唯一显示的是.dummy(我不知道那是什么,但我有一种预感,这不是我的问题的根源)。

That is where the mysql.sockfile is suppose to be located. Does anyone know of a way to fix this. Maybe I need to create the mysql.sockfile but I wouldn't know what to put in it.

这就是mysql.sock文件所在的位置。有谁知道解决这个问题的方法。也许我需要创建mysql.sock文件,但我不知道该放什么。

回答by davidcondrey

Test

测试

If you attempt to start MySQL using the full path it should work

如果您尝试使用完整路径启动 MySQL,它应该可以工作

/Applications/MAMP/Library/bin/mysql -u root -p


Fix

使固定

If that works, then you can set it to work normally by running

如果可行,那么您可以通过运行将其设置为正常工作

sudo ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock


Resolution

解析度

Now MySQL should work normally

现在 MySQL 应该可以正常工作了

mysql -u root -p

回答by Tur1ng

I know this is late, but if ever someone is searching this (as I was tonight, but I found the solution), here's what worked for me:

我知道这已经晚了,但是如果有人在搜索这个(就像我今晚一样,但我找到了解决方案),这对我有用:

I opened MAMP and had to click "USE default Apache and MySQL ports". (80 and 3306 instead of 8888 and 8889). That seemed to fix the issue.

我打开 MAMP 并必须单击“使用默认的 Apache 和 MySQL 端口”。(80 和 3306 而不是 8888 和 8889)。这似乎解决了这个问题。

回答by Prakhar Agarwal

Mysql server has not started.

Mysql 服务器还没有启动。

mysqld stop
mysql.server start

回答by ValRob

Silly solution... But in my case, I didnt start the mysql server. So, look that also!

愚蠢的解决方案......但在我的情况下,我没有启动mysql服务器。所以,看那个!

回答by afilbert

If you'd rather avoid changing ports through MAMP or options in my.cnf file, it might be useful to try forcing a TCP connection via the following on the command line:

如果您不想通过 MAMP 或 my.cnf 文件中的选项更改端口,尝试通过命令行上的以下内容强制 TCP 连接可能会很有用:

/Applications/MAMP/Library/bin/mysql -h 127.0.0.1 -P 8889 -u root

/Applications/MAMP/Library/bin/mysql -h 127.0.0.1 -P 8889 -u root

Remembering to set the port is important if it's anything other than the mysql default of 3306.

如果端口不是 mysql 默认的 3306,记住设置端口很重要。

The -Pparameter allows you to set the port.

-P参数允许您设置端口。

MAMP's default port is 8889, but you can verify what yours is set to easily via the MAMP WebStart page while MAMP is running:

MAMP 的默认端口是 8889,但您可以在 MAMP 运行时通过 MAMP WebStart 页面轻松验证您的端口设置:

http://localhost:8888/MAMP/

http://localhost:8888/MAMP/

It'll look similar to this:

它看起来类似于:

enter image description here

在此处输入图片说明

回答by Saleh Enam Shohag

I faced the same problem. When i start MAMP separately, then the problem gone. And issuing following command worked fine.

我遇到了同样的问题。当我单独启动 MAMP 时,问题就消失了。并发出以下命令工作正常。

mysql -u root -p