我在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)
这个错误意味着什么?我该怎么解决呢?
当前回答
如果你在OSX和XAMPP上,那么请遵循以下步骤:
感谢Jackstine的回答,我得以做到以下几点:
$ cat ~/.my.cnf
[mysql]
# CLIENT #
port = 3306
socket = /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock
我希望这能在我将来忘记的时候再次帮助我!
其他回答
我一直回到这篇文章,我已经遇到这个错误好几次了。这可能与在重新安装后导入所有数据库有关。
我用的是自制啤酒。唯一能帮我解决问题的是
sudo mkdir /var/mysql
sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
今天早上,在我的机器决定关闭一夜之后,这个问题又出现了。现在唯一能解决这个问题的就是升级mysql。
brew upgrade mysql
在您的终端上使用MySQL命令之前,您需要启动MySQL。为此,运行brew services start mysql。默认情况下,brew安装MySQL数据库时不需要root密码。要确保安全,请运行mysql_secure_installation。
连接时执行:mysql -uroot。Root是这里的用户名。
这个问题与/usr/local/var/mysql文件夹访问有关,我删除这个文件夹并重新安装mysql。
用brew卸载mysql: 卸载mysql 执行rm -r /usr/local/var/mysql Brew install mysql@8.0 Mysql -u root
这个解决方案很适合我! 但是你丢失了所有的数据库!警告!
升级到Catalina OS后遇到类似的问题。运行mysqld命令后,我发现日志文件有一些问题。对其他人来说可能不一样。
$ mysqld
问题是
2019-10-16T04:58:59.174474Z 0 [ERROR] Could not open file '/var/log/mysql/error.log' for error logging: No such file or directory
2019-10-16T04:58:59.174508Z 0 [ERROR] Aborting
通过创建它并应用适当的权限来解决它。
sudo mkdir -p /var/log/mysql
sudo touch /var/log/mysql/error.log
sudo chown -R _mysql:mysql /var/log/mysql/
重新启动MySQL
brew services restart mysql@5.7
问题解决了。
mysql -uroot -proot
在我的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连接。