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

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

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


当前回答

对于我的例子,只需将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>

其他回答

我一直回到这篇文章,我已经遇到这个错误好几次了。这可能与在重新安装后导入所有数据库有关。

我用的是自制啤酒。唯一能帮我解决问题的是

sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock

今天早上,在我的机器决定关闭一夜之后,这个问题又出现了。现在唯一能解决这个问题的就是升级mysql。

brew upgrade mysql

运行sudo chown _mysql /usr/local/var/mysql/*在尝试了所有这些SO答案中的大量选项后终于帮助了我。权限问题可能是由于机器关闭不当引起的。

没有工作。我只是重新安装mysql(不要担心你的数据保持不变)。

然后开始使用

sudo mysql.server start

这是所有。酿造服务mysql启动不启动mysql。

MacOS Monterey上。

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

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

对于我的例子,只需将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>