我在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”即可
其他回答
对于我的例子,只需将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>
在安装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
我一直回到这篇文章,我已经遇到这个错误好几次了。这可能与在重新安装后导入所有数据库有关。
我用的是自制啤酒。唯一能帮我解决问题的是
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
今天早上,在我的机器决定关闭一夜之后,这个问题又出现了。现在唯一能解决这个问题的就是升级mysql。
brew upgrade mysql
这解决了我的问题,当我重新启动mysql服务。运行:
brew services start 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)现在,它起作用了。