我在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)
这个错误意味着什么?我该怎么解决呢?
当前回答
Homebrew绝对不会使用标准的重新安装来修复权限,并且追踪哪个文件夹/文件损坏将花费比它值得的更长的时间。
在这种情况下-吹走mysql安装手动和重新安装通过自制。大约需要2分钟。
cd /usr/local/var
Sudo rm -rf mysql
安装mysql
Homebrew默认安装mysql是不安全的,所以如果你想要密码:
mysql_secure_installation
然后点火。
MySQL -uroot
其他回答
在您的终端上使用MySQL命令之前,您需要启动MySQL。为此,运行brew services start mysql。默认情况下,brew安装MySQL数据库时不需要root密码。要确保安全,请运行mysql_secure_installation。
连接时执行:mysql -uroot。Root是这里的用户名。
下面我包括了最新的说明从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和我的方式。
我已经尝试了所有可能的方法来解决这个问题,比如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
这发生在自制程序安装之后,由于权限问题而发生。下面的命令解决了这个问题。
sudo chown -R _mysql:mysql /usr/local/var/mysql
sudo mysql.server start
试试这个
rm -rf /usr/local/var/mysql && brew postinstall mysql@5.7 && brew services restart mysql@5.7