我正在尝试在mac os 10.6上使用Homebrew by brew安装MySQL 5.1.52。

一切都很顺利,我也成功地使用mysql_install_db。 然而,当我试图连接到服务器使用:

/usr/local/Cellar/mysql/5.1.52/bin/mysqladmin -u root password 'mypass'

我得到:

/usr/local/Cellar/mysql/5.1.52/bin/mysqladmin: connect to server at 'localhost' 
failed error: 'Access denied for user 'root'@'localhost' (using password: NO)'

我尝试访问mysqladmin或mysql使用-u root - root以及, 但是有没有密码都不行。

这是全新机器上的全新安装,据我所知,新安装必须在没有根密码的情况下访问。我还试过:

/usr/local/Cellar/mysql/5.1.52/bin/mysql_secure_installation

但我也得到了

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

当前回答

我认为如果已经安装了旧版本的mysql,就会出现这种情况。我也遇到了同样的问题,上面的解决方案对我都不起作用。我是这样安排的:

使用brew的remove & cleanup命令,卸载launchctl脚本,然后删除mysql目录在/usr/local/var,删除我现有的/etc/my.cnf(留给你,如果它适用)和launchctl plist

更新plist的字符串。还要注意,您的备用安全脚本目录将基于您正在安装的MySQL版本。

循序渐进:

brew remove mysql

brew cleanup

launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

sudo rm -rf /usr/local/var/mysql

然后我从头开始:

installed mysql with brew install mysql ran the commands brew suggested: (see note: below) unset TMPDIR mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp Start mysql with mysql.server start command, to be able to log on it Used the alternate security script: /usr/local/Cellar/mysql/5.5.10/bin/mysql_secure_installation Followed the launchctl section from the brew package script output such as, #start launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist #stop launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

注意:啤酒清理的——force位也会清理过时的酒桶,这是一个新的自制啤酒功能。

注意第二点:一个评论者说第二步不是必需的。我不想测试它,所以是YMMV!

其他回答

尝试授予权限命令mysql

好吧,我也遇到过同样的问题,但我已经解决了。由于某种原因,mysql_secure_installation脚本在使用Homebrew安装mysql时不能开箱即用,所以我手动安装了。在CLI中输入:

mysql -u root

这样你就可以进入mysql了。现在执行以下操作(取自mysql_secure_installation):

UPDATE mysql.user SET Password=PASSWORD('your_new_pass') WHERE User='root';
DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
DELETE FROM mysql.user WHERE User='';
DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'
DROP DATABASE test;
FLUSH PRIVILEGES;

现在退出并返回mysql: mysql -u root -p

删除/opt/homebrew/var/mysql就可以了。显然有mysql数据(包括密码),所以上述所有操作都是徒劳的。

尝试解决方案,我提供的MariaDB,高变化,它与MySQL的工作也:

MacOSX homebrew mysql root密码

简而言之,请尝试使用您的用户名登录!没有根。

尝试使用与MacOS帐户用户名相同的名称,例如johnsmit。

要以root用户登录,请执行以下命令:

mysql -u johnsmit

我刚才也遇到了同样的问题。如果你酿造信息mysql,并按照步骤,它看起来像根密码应该是new-password,如果我没记错的话。我看到的和你看到的一样。这篇文章对我帮助最大。

结果发现我没有为自己创建任何账户。当我登录后运行mysqld_safe和做选择*从用户;没有返回任何行。我打开mysqld_safe运行的MySQLWorkbench,并添加了一个根帐户和我所期望的所有privs。这对我来说很有效。