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

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

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


当前回答

指定数据目录/usr/local/var/mysql/不可用。您可以删除服务器添加到其中的所有文件。

MacOS: $brew服务停止mysql $brew服务列表 卸载mysql 安装mysql $brew postinstall mysql 如果发现任何错误,则运行这些cmd ! 警告:这将删除该服务器上的所有数据库: $sudo rm -rf /usr/local/var/mysql $sudo rm /usr/local/etc/my.cnf $brew postinstall mysql $brew服务启动mysql mysql_secure_installation美元 安全安装完成后运行

$mysql -u root -p

恭喜你已经安装好mysql了!

其他回答

在做了几个小时之后,对我有用的是 进入/etc/mysql/,编辑my.cnf文件。添加以下内容

[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock

下面我包括了最新的说明从brew安装mysql,以便更新搜索这个问题可以受益:

$ brew install mysql
==> Downloading https://homebrew.bintray.com/bottles/mysql-5.6.26.yosemite.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring mysql-5.6.26.yosemite.bottle.1.tar.gz

To connect:
    mysql -uroot

To have launchd start mysql at login:
  ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
  launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Or, if you don't want/need launchctl, you can just run:
  mysql.server start

在我的情况下,我现在通过launchctl load加载mysql ~/Library/LaunchAgents/homebrew.mx .mysql。Plist,然后能够启动$ 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>

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

指定数据目录/usr/local/var/mysql/不可用。您可以删除服务器添加到其中的所有文件。

MacOS: $brew服务停止mysql $brew服务列表 卸载mysql 安装mysql $brew postinstall mysql 如果发现任何错误,则运行这些cmd ! 警告:这将删除该服务器上的所有数据库: $sudo rm -rf /usr/local/var/mysql $sudo rm /usr/local/etc/my.cnf $brew postinstall mysql $brew服务启动mysql mysql_secure_installation美元 安全安装完成后运行

$mysql -u root -p

恭喜你已经安装好mysql了!