我在Mac OS X Mountain Lion上安装了MySQL,但当我尝试MySQL -u root时,我得到了以下错误:

错误2002 (HY000):无法通过套接字/tmp/ MySQL连接到本地MySQL服务器。袜子”(2)

这个错误意味着什么?我该怎么解决呢?


当前回答

在我的情况下,安装完MAMP后,从终端访问mysql会给出相同的套接字错误。最后,它想要的只是重新启动,而且它正在工作。

其他回答

执行命令: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都不适合我。

只需要从https://dev.mysql.com/downloads/file/?id=479114下载DMG(找到你需要的合适版本),然后让向导为我安装它,这是超级轻松的。另外一个手动步骤是将/usr/local/mysql/bin添加到PATH中。

如果酿造给你带来麻烦,我推荐这个选择。

更新-如果这仍然不能解决它,在通过DMG安装之前尝试完全清除mysql。请遵循以下说明:https://gist.github.com/vitorbritto/0555879fe4414d18569d

在您的终端上使用MySQL命令之前,您需要启动MySQL。为此,运行brew services start mysql。默认情况下,brew安装MySQL数据库时不需要root密码。要确保安全,请运行mysql_secure_installation。

连接时执行:mysql -uroot。Root是这里的用户名。

如果你正在使用Kali linux,你可能需要显式地指定主机

用 Mysql -h 127.0.0.1 -u root 127.0.0.1是您的本地主机

对于我的例子,只需将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>