我在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的权限 sudo chown -R _mysql:mysql /usr/local/var/mysql 启动MySQL进程 sudo mysql。服务器启动
如果上面的命令不能帮你解决这个问题,那就试着指定主机
mysql -u root -p h127.0.0.1
其他回答
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)现在,它起作用了。
下面我包括了最新的说明从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和我的方式。
在您的终端上使用MySQL命令之前,您需要启动MySQL。为此,运行brew services start mysql。默认情况下,brew安装MySQL数据库时不需要root密码。要确保安全,请运行mysql_secure_installation。
连接时执行:mysql -uroot。Root是这里的用户名。
正如其他人指出的,这是因为MySQL已经安装,但服务没有运行。启动MySQL服务的方法有很多种,对我有用的方法如下。
启动服务。
转到“系统首选项” 在底部窗格中应该有MySql图标。 双击启动“MySQL服务器状态”,按下“启动MySQL服务器”按钮
我的环境:
Mac Yosemite 10.10.3
安装包:/Volumes/mysql-advanced-5.6.24-osx10.8-x86_64
对于我的例子,只需将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>