我在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)
这个错误意味着什么?我该怎么解决呢?
当前回答
在终端中点击“brew services start mysql”即可
其他回答
对我来说,这就像跑步一样简单:
/usr/local/opt/mysql/bin/mysqld_safe
而不是mysqld
这可能是因为MySQL已经安装但还没有运行。
要验证它正在运行,打开活动监视器,在“所有进程”下,搜索并验证你看到了进程“mysqld”。
你可以通过安装“MySQL.prefPane”来启动它。
以下是帮助我的完整教程: http://obscuredclarity.blogspot.in/2009/08/install-mysql-on-mac-os-x.html
在安装mysql的过程中,您可能会遇到一些问题,mysql服务可能无法运行。如果是这种情况,那么可能值得尝试以下步骤重新安装mysql,然后尝试连接。
sudo chown -R $(whoami) /usr/local/var
sudo chown -R $(whoami) /Library/Caches/Homebrew
brew uninstall mysql
brew install mysql
mysql.server start
mysql -uroot
对于我的例子,只需将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>
在我的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连接。