在linux初始化完成mysql之后,使用默认随机生成的root密码登录mysql,会出现无法执行任何命令的情况:

You must reset your password using ALTER USER statement before executing this
statement.

然而此时的root并不能执行上述的ALTER USER 语句,因为root此时没有任何DML权限。

通过mysql的无验证登录方式对user表进行修改,也可以用于重置root用户密码。

1、结束所有mysql进程:

service mysql.server stop 具体mysql服务名称根据自身配置修改

killall -TERM mysql

killall -TERM msqld

2、使用无验证模式启动mysql

mysqld_safe --skip-grant-tables &

看到mysql守护线程启动说明设置成功:




否则mysql的线程还没有完全关闭,重复1操作:




3、检查user表

此时使用mysql -u root 即可登录mysql,无须密码。

use mysql;

desc user;


可以看到mysql5.7.19之后的user表的密码字段不再是password,而是authentication_string,password_expired则是过期:




update user set authenticatio_string=password('1234'),password_expired='N'
where user='root';

select authentication_string,password_expired from user where user='root';




然后更新权限:flush privileges;

4、恢复默认方式启动mysql

重复步骤1关闭所有mysql进程。

mysqld_safe --user=mysql & 恢复正常模式。

mysql -u root -p 此时需要输入-p用密码登录:






友情链接
ioDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信