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

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

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


当前回答

只有这一点让我成功了 酿造服务启动——全部启动 (试完所有答案后)

其他回答

如果你正在使用Kali linux,你可能需要显式地指定主机

用 Mysql -h 127.0.0.1 -u root 127.0.0.1是您的本地主机

这发生在自制程序安装之后,由于权限问题而发生。下面的命令解决了这个问题。

sudo chown -R _mysql:mysql /usr/local/var/mysql

sudo mysql.server start

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

对我来说,这就像跑步一样简单:

/usr/local/opt/mysql/bin/mysqld_safe

而不是mysqld

这个问题与/usr/local/var/mysql文件夹访问有关,我删除这个文件夹并重新安装mysql。

用brew卸载mysql: 卸载mysql 执行rm -r /usr/local/var/mysql Brew install mysql@8.0 Mysql -u root

这个解决方案很适合我! 但是你丢失了所有的数据库!警告!