一.系统版本

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 '密码';  
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐