我在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服务的方法有很多种,对我有用的方法如下。
启动服务。
转到“系统首选项” 在底部窗格中应该有MySql图标。 双击启动“MySQL服务器状态”,按下“启动MySQL服务器”按钮
我的环境:
Mac Yosemite 10.10.3
安装包:/Volumes/mysql-advanced-5.6.24-osx10.8-x86_64
其他回答
我经历了这个问题,我设法运行mysql服务器使用下面的解决方案
通过.dmg(https://dev.mysql.com/downloads/mysql/5.7.html)安装mysql,你会在系统首选项中看到mysql服务面板,然后从面板中启动mysql并尝试
Mysql -u root -p
附图供参考
如果你在OSX和XAMPP上,那么请遵循以下步骤:
感谢Jackstine的回答,我得以做到以下几点:
$ cat ~/.my.cnf
[mysql]
# CLIENT #
port = 3306
socket = /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
我希望这能在我将来忘记的时候再次帮助我!
对于我的例子,只需将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>
如果你正在使用Kali linux,你可能需要显式地指定主机
用 Mysql -h 127.0.0.1 -u root 127.0.0.1是您的本地主机
在安装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