我在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服务器没有运行。
这是由于MySQL没有正确设置在我的机器上,因此不能运行。
为了解决这个问题,我使用了一个在Mac OSX Mountain Lion上安装MySQL的脚本,该脚本必须安装丢失的文件。
链接如下:http://code.macminivault.com/
重要提示:该脚本将根密码设置为随机生成的字符串,保存在Desktop上,因此请注意不要删除该文件并记录密码。它还会在您的系统首选项中安装MySQL管理器。我也不确定是否删除任何现有的数据库,所以要小心。
其他回答
这发生在自制程序安装之后,由于权限问题而发生。下面的命令解决了这个问题。
sudo chown -R _mysql:mysql /usr/local/var/mysql
sudo mysql.server start
下面我包括了最新的说明从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和我的方式。
对我来说,这就像跑步一样简单:
/usr/local/opt/mysql/bin/mysqld_safe
而不是mysqld
对于我的例子,只需将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>
执行命令: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