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

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

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


当前回答

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

其他回答

没有工作。我只是重新安装mysql(不要担心你的数据保持不变)。

然后开始使用

sudo mysql.server start

这是所有。酿造服务mysql启动不启动mysql。

MacOS Monterey上。

执行命令: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已经安装但还没有运行。

要验证它正在运行,打开活动监视器,在“所有进程”下,搜索并验证你看到了进程“mysqld”。

你可以通过安装“MySQL.prefPane”来启动它。

以下是帮助我的完整教程: http://obscuredclarity.blogspot.in/2009/08/install-mysql-on-mac-os-x.html

如果你在OSX和XAMPP上,那么请遵循以下步骤:

感谢Jackstine的回答,我得以做到以下几点:

$ cat ~/.my.cnf

[mysql]

# CLIENT #
port                           = 3306
socket                         = /Applications/XAMPP/xamppfiles/var/mysql/mysql.sock

我希望这能在我将来忘记的时候再次帮助我!

我设法通过将localhost更改为127.0.0.1来解决这个问题