MySql错误1045(28000):用户'root'@'localhost'的访问被拒绝(使用密码:否) [英] MySql ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

查看:109
本文介绍了MySql错误1045(28000):用户'root'@'localhost'的访问被拒绝(使用密码:否)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试过StackOverflow的多种解决方案,但没有取得任何成功.我在Mac OSX(Sierra 10.12.3)上尝试创建新的数据库和用户.从终端输入:

I've tried multiple solutions from StackOverflow but haven't had any success. I'm on Mac OSX (Sierra 10.12.3) trying to create a new database and user. From terminal I enter:

mysql -u root

输出此错误:

错误1045(28000):用户'root'@'localhost'的访问被拒绝(使用密码:NO)

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

要尝试解决该问题,我从系统偏好设置"中停止了mysql,然后从键入的终端中停止了运行:

To try and resolve it I stopped mysql from 'System Preferences', then from terminal typed:

sudo mysqld_safe —skip-grant-tables

我打开了第二个标签,然后输入:

I opened a second tab and entered:

mysql -u root

然后从mysql中获取

Then from in mysql:

update mysql.user set password_expired = 'N', authentication_string=PASSWORD('newpassword') where user = 'root';

flush privileges;

然后我重新启动计算机(使用CMD + C终止进程不起作用).重新启动后,尝试mysql -u root仍然会产生相同的错误.

I then restart the computer (killing the process with CMD + C doesn't work). After restarting, trying mysql -u root still produces the same error.

我能够通过MySQL客户端和非root用户访问mysql.

I am able to access mysql via a MySQL client and a non-root user.

感谢您的帮助.

推荐答案

仅需确认:您确定您正在运行MySQL 5.7,而不是MySQL 5.6或更早版本.并且插件列包含"mysql_native_password". (在MySQL 5.7之前,密码哈希存储在名为password的列中.从MySQL 5.7开始,删除了password列,而密码has已存储在authentication_string列中.)并且您还验证了身份验证字符串的内容.与PASSWORD('mysecret')的返回值匹配.另外,是否有理由我们针对mysql.user表使用DML而不是使用SET PASSWORD FOR语法? – spencer7593

Just to confirm: You are sure you are running MySQL 5.7, and not MySQL 5.6 or earlier version. And the plugin column contains "mysql_native_password". (Before MySQL 5.7, the password hash was stored in a column named password. Starting in MySQL 5.7, the password column is removed, and the password has is stored in the authentication_string column.) And you've also verified the contents of authentication string matches the return from PASSWORD('mysecret'). Also, is there a reason we are using DML against the mysql.user table instead of using the SET PASSWORD FOR syntax? – spencer7593

因此,基本上只要确保插件"列中包含"mysql_native_password"即可.

So Basically Just make sure that the Plugin Column contains "mysql_native_password".

不是我的工作,但我阅读了评论,并注意到这被认为是答案,但尚未发布为可能的答案.

Not my work but I read comments and noticed that this was stated as the answer but was not posted as a possible answer yet.

这篇关于MySql错误1045(28000):用户'root'@'localhost'的访问被拒绝(使用密码:否)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆