我在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文件夹中的所有数据库
我在Homebrew上安装了MySQL,唯一解决这个问题的方法就是重新安装MySQL。
在我公司的笔记本电脑上,我没有通过Homebrew卸载MySQL的权限:
$ brew uninstall mysql --ignore-dependencies
Uninstalling /usr/local/Cellar/mysql/8.0.12... (255 files, 233.0MB)
Error: Permission denied @ dir_s_rmdir - /usr/local/Cellar/mysql/8.0.12
所以,我手动删除并重新安装MySQL:
$ sudo rm -rf /usr/local/Cellar/mysql
$ brew cleanup
$ sudo rm -rf /usr/local/var/mysql
$ brew install mysql
这奏效了!
其他回答
在做了几个小时之后,对我有用的是 进入/etc/mysql/,编辑my.cnf文件。添加以下内容
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
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都不适合我。
只需要从https://dev.mysql.com/downloads/file/?id=479114下载DMG(找到你需要的合适版本),然后让向导为我安装它,这是超级轻松的。另外一个手动步骤是将/usr/local/mysql/bin添加到PATH中。
如果酿造给你带来麻烦,我推荐这个选择。
更新-如果这仍然不能解决它,在通过DMG安装之前尝试完全清除mysql。请遵循以下说明:https://gist.github.com/vitorbritto/0555879fe4414d18569d
对于我的例子,只需将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>
我已经尝试了所有可能的方法来解决这个问题,比如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