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

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

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


当前回答

Homebrew绝对不会使用标准的重新安装来修复权限,并且追踪哪个文件夹/文件损坏将花费比它值得的更长的时间。

在这种情况下-吹走mysql安装手动和重新安装通过自制。大约需要2分钟。

cd /usr/local/var

Sudo rm -rf mysql

安装mysql

Homebrew默认安装mysql是不安全的,所以如果你想要密码:

mysql_secure_installation

然后点火。

MySQL -uroot

其他回答

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

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

而不是mysqld

我建议你去跑步

  mysql.server start

在去之前

  mysql -u root -p

为了确保mysql服务器在登录之前正在运行

当你启动/重启一台没有运行mysql服务器的机器时,这种情况会发生很多次。

如果你在OSX和XAMPP上,那么请遵循以下步骤:

感谢Jackstine的回答,我得以做到以下几点:

$ cat ~/.my.cnf

[mysql]

# CLIENT #
port                           = 3306
socket                         = /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock

我希望这能在我将来忘记的时候再次帮助我!

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

在我的mac m1 macOS Monterey上安装MySQL后,使用brew安装MySQL,我得到了以下信息:

[System] [MY-013169] [Server] /opt/homebrew/Cellar/mysql/8.0.27_1/bin/mysqld (mysqld 8.0.27) initializing of server in progress as process 3624

[ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.

[ERROR] [MY-013236] [Server] The designated data directory /opt/homebrew/var/mysql/ is unusable. You can remove all files that the server added to it.

[ERROR] [MY-010119] [Server] Aborting

[System] [MY-010910] [Server] /opt/homebrew/Cellar/mysql/8.0.27_1/bin/mysqld: Shutdown complete (mysqld 8.0.27)  Homebrew.

还有这个警告:

Warning: The post-install step did not complete successfully You can
try again using:   brew postinstall mysql

之后,我尝试使用brew services启动MySQL,我得到了这个错误:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket
'/tmp/mysql.sock' (2)

我设法修复它使用:

> rm -rf ~/opt/homebrew/var/mysql/
> brew postinstall mysql

现在您可以使用mysql -uroot或mysql -uroot -p连接。