解决密码正确但Access denied for user ‘root’@‘localhost’ (using password: YES)问题

一.系统版本

Linux:CentOS-7-x86_64-DVD-1810.iso
mysql:mysql-5.7.27-1.el7.x86_64.rpm-bundle

二.问题

登陆数据库,密码正确但出现了Access denied for user ‘root’@‘localhost’ (using password: YES)的问题。

三.解决

1.停止mysql服务

systemctl stop mysqld

2.配置文件,跳过访问权限

vim /etc/my.cnf

在这里插入图片描述

skip_grant_tables

3.重启mysql

systemctl restart mysqld

4.登陆数据库,不需要密码

mysql -u root -p

5.切换数据库到mysql

use  mysql;

6.修改root密码,我的mysql版本密码字段是authentication_string

 update  user set  authentication_string=  password('123456')where  user='root';

7.刷新,退出

刷新:flush privileges;
退出:quit

8.再次进入配置文件,并注释掉skip_grant_tables

9.重启mysql服务

10.登陆,使用刚刚设置的密码,登陆后会要求修改密码

11.设置密码安全策略

set global validate_password_length=4;
set global validate_password_policy=LOW;

12.修改密码

alter user user() identified by '654321';

13.给予root用户权限

GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY '密码';  
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

愛沢かりん

感谢您对我的支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值