mysql5.7 忘记密码

  • 如果 MySQL 正在运行,首先杀掉:
killall -TERM mysqld
  • 启动mysql
mysqld_safe --skip-grant-tables &
如果此时不想被远程连接:
mysqld_safe --skip-grant-tables --skip-networking &
  • 使用mysql连接server 更改密码
update mysql.user set authentication_string=password('123qwe') where user='root';
flush privileges;
quit;
  • 修改完毕 重启
killall -TERM mysqld
mysqld_safe &
  • 使用mysql连接server后不能执行其他命令,提示:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. 需要重置密码:
SET PASSWORD = PASSWORD('new password');
ALTER USER 'root'@'localhost' PASSWORD EXPIRE NEVER;
flush privileges;

注意:SET PASSWORD 的时候可能会报错:ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 原因是密码强度太低,需要更换复杂密码,大小写字母,数字,其他符号

猜你喜欢

转载自blog.csdn.net/liyinwang/article/details/71159774