Mysql数据库报错ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)

问题

今天公司Mysql数据库密码不知道被哪位神人改了,报错:ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES),如图:
Mysql数据库报错ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)

解决

百度了很多都是windows下解决方案,只能照着试试,没想到成功了

1、修改my.cnf

使用vi编辑器,在mysql配置文件【mysqld】下添加skip-grant-tables

vi /etc/my.cnf

Mysql数据库报错ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: YES)
wq保存

2、重启Mysql服务:service mysqld restart

3、免密登录MySQL

然后再次进入到终端当中,敲入 mysql -u root -p 命令然后回车,当需要输入密码时,直接按enter键,便可以不用密码登录到数据库当中

4、输入命令修改密码

flush privileges
set password for '用户名'@'mysql服务器ip' = password('新密码')

5、将配置文件还原,重启Mysql服务

相关文章:

  • 2022-02-18
  • 2021-06-12
  • 2021-04-16
  • 2021-06-15
  • 2022-12-23
猜你喜欢
  • 2021-12-04
  • 2021-10-25
  • 2021-05-16
  • 2021-07-17
相关资源
相似解决方案