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

8 篇文章 0 订阅

问题:

C:\Users\ASDS>mysql -uroot -p

Enter password: **********

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

 

出现这种情况的原因:

  1. 密码输入错误
  2. Mysql服务未开启

 

解决办法:

进入mysql安装目录:找到my.ini

Win10系统的是在 C:\ProgramData\MySQL\MySQL Server 5.7目录下

编辑my.ini 添加一行代码:skip-grant-tables

如图:

 

进入mysql数据库

mysql -uroot -p

密码不用填,直接回车

进入数据库

use mysql  #进入mysql数据库进行设置

desc user #查看user表结构

 

| plugin                 | char(64)                          | NO   |     | mysql_native_password |       |

| authentication_string  | text                              | YES  |     | NULL                  |       |

| password_expired       | enum('N','Y')                     | NO   |     | N                     |       |

| password_last_changed  | timestamp                         | YES  |     | NULL                  |       |

| password_lifetime      | smallint(5) unsigned              | YES  |     | NULL                  |       |

| account_locked         | enum('N','Y')                     | NO   |     | N                     |       |

+------------------------+-----------------------------------+------+-----+-----------------------+-------+

45 rows in set (0.01 sec)

 

mysql> select user,authentication_string where user="root";

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where user="root"' at line 1

mysql> select user,authentication_string from user where user="root";

+------+-------------------------------------------+

| user | authentication_string                     |

+------+-------------------------------------------+

| root | *33E5325E7E3283C80E0C495434954FD74919C12D |

+------+-------------------------------------------+

1 row in set (0.01 sec)

#修改root用户的密码:

mysql> update user set authentication_string = password('root'), password_expired = 'N', password_last_changed = now() where user = 'root';

Query OK, 1 row affected, 1 warning (0.01 sec)

Rows matched: 1  Changed: 1  Warnings: 1

 

mysql> select user,authentication_string from user where user="root";

+------+-------------------------------------------+

| user | authentication_string                     |

+------+-------------------------------------------+

| root | *81F5E21E35407D884A6CD4A731AEBFB6AF209E1B |

+------+-------------------------------------------+

1 row in set (0.00 sec)

#修改成功!

回到my.ini文件,将刚刚添加的代码删除,保存

重新启动mysql服务,我的mysql版本是5.7,win10系统

以管理员身份运行命令行窗口关闭或开启mysql服务:

net start 服务名称  

举例:

net stop mysql57

net start mysql57

Mysql服务启动成功,就可以用刚刚设置的用户用户密码进入mysql数据库了

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值