我在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)
这个错误意味着什么?我该怎么解决呢?
当前回答
执行命令:brew info mysql
按照说明做。由公式中的描述可知:
Set up databases to run AS YOUR USER ACCOUNT with:
unset TMPDIR
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
To set up base tables in another folder, or use a different user to run
mysqld, view the help for mysql_install_db:
mysql_install_db --help
and view the MySQL documentation:
* http://dev.mysql.com/doc/refman/5.5/en/mysql-install-db.html
* http://dev.mysql.com/doc/refman/5.5/en/default-privileges.html
其他回答
解决方案围绕:
修改MySQL的权限 sudo chown -R _mysql:mysql /usr/local/var/mysql 启动MySQL进程 sudo mysql。服务器启动
如果上面的命令不能帮你解决这个问题,那就试着指定主机
mysql -u root -p h127.0.0.1
我经历了这个问题,我设法运行mysql服务器使用下面的解决方案
通过.dmg(https://dev.mysql.com/downloads/mysql/5.7.html)安装mysql,你会在系统首选项中看到mysql服务面板,然后从面板中启动mysql并尝试
Mysql -u root -p
附图供参考
运行sudo chown _mysql /usr/local/var/mysql/*在尝试了所有这些SO答案中的大量选项后终于帮助了我。权限问题可能是由于机器关闭不当引起的。
对于我的例子,只需将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>
在尝试了许多解决方案之后,似乎最终成功的是通过IP连接。不再文件套接字被随机删除。
只需更新MySQL客户端配置(例如/usr/local/etc/my.cnf):
[client]
port = 3306
host=127.0.0.1
protocol=tcp