我在Mac OS X Mountain Lion上安装了MySQL,但当我尝试MySQL -u root时,我得到了以下错误:
错误2002 (HY000):无法通过套接字/tmp/ MySQL连接到本地MySQL服务器。袜子”(2)
这个错误意味着什么?我该怎么解决呢?
我在Mac OS X Mountain Lion上安装了MySQL,但当我尝试MySQL -u root时,我得到了以下错误:
错误2002 (HY000):无法通过套接字/tmp/ MySQL连接到本地MySQL服务器。袜子”(2)
这个错误意味着什么?我该怎么解决呢?
当前回答
我找到了解决问题的办法。这确实是因为我的MySQL服务器没有运行。
这是由于MySQL没有正确设置在我的机器上,因此不能运行。
为了解决这个问题,我使用了一个在Mac OSX Mountain Lion上安装MySQL的脚本,该脚本必须安装丢失的文件。
链接如下:http://code.macminivault.com/
重要提示:该脚本将根密码设置为随机生成的字符串,保存在Desktop上,因此请注意不要删除该文件并记录密码。它还会在您的系统首选项中安装MySQL管理器。我也不确定是否删除任何现有的数据库,所以要小心。
其他回答
我花了好长时间才想明白。我在评论里看到的。在使用brew安装mysql后,启动服务(可能使用sudo brew services start mysql),然后运行:
$ mysqld
MySQL应该在后面为你运行。
我建议你去跑步
mysql.server start
在去之前
mysql -u root -p
为了确保mysql服务器在登录之前正在运行
当你启动/重启一台没有运行mysql服务器的机器时,这种情况会发生很多次。
我已经尝试了所有可能的方法来解决这个问题,比如ln -s /var/lib/mysql/mysql.袜子/ tmp / mysql。Sock,卸载并重新安装mysql,确保mysql在xampp上运行,但没有一个仍然工作。
最后,我打开my.cnf(配置文件)并复制套接字路径(确保复制完整路径,否则它将不起作用)。然后在我的终端中执行这个命令
mysql --socket=/Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
瞧,mysql启动了。
这个解决方案只会工作,如果你的MySQL显示在Xampp/Ampps上运行,但在终端它仍然没有连接到正确的套接字时,你已经尝试了类似的:
./mysql -u root
or
brew services start mysql
指定数据目录/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了!
在我的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连接。