Linux入门教程:centos7忘记mysql密码,


个人环境

mysql 5.7.16 centos 7.4

1. 修改mysql配置文件

编辑配置文件

vim /etc/my.cnf

按i在[mysqld]中添加skip-grant-tables,即跳过权限认证

skip-grant-tables

按esc后输入:wq保存退出

2. 重启mysql

输入命令重启

service mysqld restart

3. 登录mysql

mysql -u root -p

无需输入密码直接回车进入mysql

4. 修改mysql的root密码

选择mysql数据库

use mysql;

修改root密码 (密码需要满足mysql的密码策略,见底部)

update user set authentication_string=password('你的密码') where user='root';

刷新权限

flush privileges;

退出mysql

quit;

5. 修改/etc/my.cnf 删除skip-grant-tables

6. 重启mysql

service mysqld restart

7. 再次登录mysql,出现错误提示

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
修改密码即可

set password=password("密码");

密码策略如下:

至少8位 至少包含1位特殊字符 至少包含大小写混合 至少1位数字 如果出现1819错误,代表密码不符合要求
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

相关内容