MySQL 我的 ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/49091983/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 22:52:50  来源:igfitidea点击:

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

mysqlaccess-denied

提问by L. Drail

When I try to connect the MySQL Server by command:

当我尝试通过命令连接 MySQL 服务器时:

mysql -u root -p

I get error "Access denied". I'm sure that the password is right.

我收到错误“拒绝访问”。我确定密码是正确的。

When I use the

当我使用

mysqld --defaults-files "xxx\my.ini" --console --skip-grant-tables

option, I can access in, but when I quit this, access is denied again.

选项,我可以访问,但是当我退出时,访问再次被拒绝。

How could I sovle it?

我怎么能解决它?

回答by Ortomala Lokni

You can reset the root password.

您可以重置root密码。

For MySQL 5.7.6 and later:

对于 MySQL 5.7.6 及更高版本:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';

MySQL 5.7.5 and earlier:

MySQL 5.7.5 及更早版本:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');

This can be dangerous, read the full official instructions before: How to Reset the Root Password?

这可能很危险,请先阅读完整的官方说明:如何重置 Root 密码?

回答by Korteby Farouk

Try Resetting the Root Password: Generic Instructions

尝试重置根密码:通用说明

  1. Restart mysql with the --skip-grant-tables option
  2. In the mysql client : FLUSH PRIVILEGES;
  3. SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
  1. 使用 --skip-grant-tables 选项重新启动 mysql
  2. 在 mysql 客户端中: FLUSH PRIVILEGES;
  3. SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');