我在Mac OS X Mountain Lion上安装了MySQL,但当我尝试MySQL -u root时,我得到了以下错误:

错误2002 (HY000):无法通过套接字/tmp/ MySQL连接到本地MySQL服务器。袜子”(2)

这个错误意味着什么?我该怎么解决呢?


当前回答

在使用了以上所有的解决方案后,没有一个对我有效,但这个有效。

如果你已经使用HomeBrew安装了MySQL,然后检查系统首选项> MySQL在你的mac中,MySQL服务器已经停止,如果它正在运行,请单击停止MySQL服务器,并从终端写入命令mysqlserver.start启动MySQL。

如果它不工作,你也可以尝试:-

如果您已经安装了MySQL工作台,那么只需卸载MySQL工作台和MySQL,然后先安装MySQL,再安装MySQL工作台。

其他回答

在您的终端上使用MySQL命令之前,您需要启动MySQL。为此,运行brew services start mysql。默认情况下,brew安装MySQL数据库时不需要root密码。要确保安全,请运行mysql_secure_installation。

连接时执行:mysql -uroot。Root是这里的用户名。

试试这个

rm -rf /usr/local/var/mysql && brew postinstall mysql@5.7 && brew services restart mysql@5.7

在我的情况下,安装完MAMP后,从终端访问mysql会给出相同的套接字错误。最后,它想要的只是重新启动,而且它正在工作。

对于我的例子,只需将host指定为127.0.0.1,而不是localhost:

$ bin/mysql -uroot -p -h127.0.0.1
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.26

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

我设法通过将localhost更改为127.0.0.1来解决这个问题