码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2020-09-16 12:13:32      阅读:52      评论:0      收藏:0      [点我收藏+]

标签:inf   The   flush   pre   ble   重启   tables   upd   alt   

在登录mysql输入密码后出现如下问题:

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

一般是密码错误引起,解决的办法是重置密码,  重置密码的第一步就是跳过MySQL的密码认证过程

查找my.cnf文件的位置

find / -name my.cnf

我的文件位置是 ./etc/my.cnf,   打开my.cnf文件

vim /etc/my.cnf

找到[mysqld],在它的后面任意下一行添加如下代码

skip-grant-tables

然后重启mysql:

systemctl stop mysqld.service
systemctl start mysqld.service

输入mysql

技术图片

用sql来修改root的密码 

在mysql数据库有一个user表,存储的是数据库用户的信息,我们需要修改的里面用户的密码;

show databases;

技术图片

命令依次为:

1.use mysql;(使用mysql数据库)
2.update user set password=password("你的密码") where user="root";     //mysql5.7版本下没有password 改成update user set authentication_string=password("你的密码") where user="root";
3.flush privileges; 
4.quit

技术图片

root账户就已经重置成新的密码了

编辑my.cnf,去掉刚才添加的内容,然后重启MySQL

 

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

标签:inf   The   flush   pre   ble   重启   tables   upd   alt   

原文地址:https://www.cnblogs.com/chong-zuo3322/p/13603154.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!