MySQL 错误 1045 (28000):MAC OSX 上的用户 'root'@'localhost'(使用密码:NO)访问被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32858216/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO) on MAC OSX
提问by Bibek Sharma
I'm trying to reinstall mysql on my MAC OS X Yosemite. for this I followed the instruction as mentioned below
我正在尝试在我的 MAC OS X Yosemite 上重新安装 mysql。为此,我按照下面提到的说明进行操作
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/MySQL*
vim /etc/hostconfig and removed the line MYSQLCOM=-YES-
rm -rf ~/Library/PreferencePanes/MySQL*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /var/db/receipts/com.mysql.*
I also tried
我也试过
brew uninstall mysql
after this I installed mysql using homebrew using command brew install mysql.
After installation when I tried to run mysql -u rootIt throws the following error
在此之后,我使用命令使用自制软件安装了 mysql brew install mysql。安装后当我尝试运行mysql -u root它会引发以下错误
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
错误 1045 (28000): 用户 'root'@'localhost' 访问被拒绝(使用密码:NO)
I didn't set password for mysql.I don't know what's going wrong.Any suggestion will be appreciated. Thank you
我没有为 mysql 设置密码。我不知道出了什么问题。任何建议将不胜感激。谢谢
回答by Ghrua
I installed mysqlwith homebrewand got the same problem as you because mysqlhas had an existing database with an existing password there. See this articlefor more details.
我安装mysql使用homebrew,并得到了同样的问题,因为你,因为mysql已经有一个现有的数据库与现有的密码存在。有关更多详细信息,请参阅此文章。
$ brew services stop mysql
$ pkill mysqld
$ rm -rf /usr/local/var/mysql/ # NOTE: this will delete your existing database!!!
$ brew postinstall mysql
$ brew services restart mysql
$ mysql -uroot
回答by Inês Gomes
Now sql generates an aliatory password that appears in the last screen.
现在 sql 生成一个显示在最后一个屏幕中的别名密码。
sudo mysql -u root -h 127.0.0.1 -p
Enter password: (aliatory password)
we can change it
我们可以改变它
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new-password';
回答by Leo LE
I have resolved this issue for myself.
我已经为自己解决了这个问题。
Please check my github with this link: https://github.com/LeVanTuan/access_sql
请使用此链接检查我的 github:https: //github.com/LeVanTuan/access_sql
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES/NO)
Fix bug access denied on macos 10.12 (Sierra)
install mysql (https://dev.mysql.com/downloads/mysql/) if already installed, skip this step
Update password of 'root' to access.
Open Terminal (Launchpad -> Other -> Terminal or (Command + space) -> Type 'terminal' )
Then type follow below:
export PATH=$PATH:/usr/local/mysql/bin/
sudo mysqld_safe --skip-grant-tables
then, restart Terminal (quit then open again)
then, keep type:
export PATH=$PATH:/usr/local/mysql/bin/
mysql -u root mysql
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
\q
sudo /usr/local/mysql/support-files/mysql.server start
extra: start mysql: sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables stop mysql: sudo /usr/local/mysql/support-files/mysql.server stop
错误 1045 (28000):用户“root”@“localhost”的访问被拒绝(使用密码:是/否)
修复在 macos 10.12 (Sierra) 上拒绝访问的错误
安装 mysql ( https://dev.mysql.com/downloads/mysql/) 如果已经安装,跳过这一步
更新“root”的密码以进行访问。
打开终端(启动板 -> 其他 -> 终端或(Command + 空格) -> 输入 'terminal' )
然后在下面输入:
导出 PATH=$PATH:/usr/local/mysql/bin/
须藤 mysqld_safe --skip-grant-tables
然后,重新启动终端(退出然后再次打开)
然后,保持输入:
导出 PATH=$PATH:/usr/local/mysql/bin/
mysql -u 根 mysql
同花顺特权;
ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';
\q
须藤/usr/local/mysql/support-files/mysql.server 启动
额外:启动mysql:sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables 停止mysql:sudo /usr/local/mysql/support-files/mysql.server stop
I hope it will help you
我希望它会帮助你
回答by R Nanthak
I tried all the commands mentioned in the stackoverflow, but nothing worked. Finally, I deleted every mysql folder in mac and reinstalled mysql. Finally the command
我尝试了stackoverflow中提到的所有命令,但没有任何效果。最后,我删除了mac中的每个mysql文件夹并重新安装了mysql。最后命令
mysql -u root
worked for me. Then atlast, I set password for the mysql root by editing the configuration file.
为我工作。最后,我通过编辑配置文件为 mysql 根设置密码。

