我在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)
这个错误意味着什么?我该怎么解决呢?
当前回答
这个问题与/usr/local/var/mysql文件夹访问有关,我删除这个文件夹并重新安装mysql。
用brew卸载mysql: 卸载mysql 执行rm -r /usr/local/var/mysql Brew install mysql@8.0 Mysql -u root
这个解决方案很适合我! 但是你丢失了所有的数据库!警告!
其他回答
在我的情况下,安装完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连接。
下面我包括了最新的说明从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和我的方式。
1)->首先启动SQL server 2)(如果不存在)你必须在你安装的地方创建一个'etc'目录 Mysql ->在其中创建一个名为“Mysql .sock”的文件。 3)然后执行下面的行
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
4)重启服务器
5)找到mysql的路径。通过在线下执行Sock '
mysql -u root -p -h 127.0.0.1 -e "select @@socket"
现在你可以看到路径->复制该路径 6)复制完成后执行以下一行
mysql -u (username) -p -S (paste the path you copied)
7)现在,它起作用了。
在安装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