我在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服务器没有启动。我通常运行stop命令,然后重新启动:
mysqld stop
mysql.server start
同样的错误,这也适用于我。
其他回答
在您的终端上使用MySQL命令之前,您需要启动MySQL。为此,运行brew services start mysql。默认情况下,brew安装MySQL数据库时不需要root密码。要确保安全,请运行mysql_secure_installation。
连接时执行:mysql -uroot。Root是这里的用户名。
如果你在OSX和XAMPP上,那么请遵循以下步骤:
感谢Jackstine的回答,我得以做到以下几点:
$ cat ~/.my.cnf
[mysql]
# CLIENT #
port = 3306
socket = /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
我希望这能在我将来忘记的时候再次帮助我!
没有工作。我只是重新安装mysql(不要担心你的数据保持不变)。
然后开始使用
sudo mysql.server start
这是所有。酿造服务mysql启动不启动mysql。
MacOS Monterey上。
我已经尝试了所有可能的方法来解决这个问题,比如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
在我的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连接。