CentOS安装mysql8以后提示Access denied for user ‘root’@’localhost’ (using password: YES)

/ 0评 / 0

其实以前出现过这个报错,也解决了,但忘记步骤,这次又出现了(貌似每次都会出现),网上搜寻了一堆解决方案,奇怪的是基本无效,这次整理步骤如下:

找到my.cnf文件,开启免密码登录:

vim /etc/my.cnf
// 在[mysqld]之下添加: "skip-grant-tables"

重启mysql服务:

sudo systemctl restart mysqld

然后,免密码登录到mysql,修改密码:

mysql -uroot -p
// 然后直接回车,进入Mysql控制台
// 切换数据库
mysql> use mysq;
// 将密码设置为空
mysql> update user set authentication_string='' where user='root';
// 刷新
mysql> flush privileges;
// 更改新密码, 如果没有改%需要将localhost改成%,开启远程登录, 'xxxx'是新密码
mysql> alter user 'root'@'%' identified by 'xxxx';

到这个地方,直接报错了:

ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

先退出mysql控制台,重新免密码登录,不选择任何数据库,执行如下指令:

mysql> show wariables like 'validate_password%';

继续执行如下指令:

mysql> set global validate_password.policy=0;
mysql> set global validate_password.length=1;

然后继续修改密码:

mysql> alter user 'root'@'%' identified by 'xxxx';

退出mysql控制台,然后将/etc/my.cnf中的 "skip-grant-tables" 注释掉,重启mysql服务器,使用密码登录即可

名言语句:天欲使其灭亡,必先使其疯狂。

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注