第一步、暂停mysql服务;
systemctl stop mysqld
第二步、修改mysql的配置文件/etc/my.cnf
vim /etc/my.cnf ##在文件添加一行;
skip-grant-tables ##译为:跳过mysql数据库的授权表;
#validate_password_length=6 ##注释掉验证密码的长度
#validate_password_policy=0 ##注释掉验证密码的策略
第三步、保存配置文件,重新启动服务;
systemctl restart mysqld
第四步、mysql 直接进入数据库修改登陆密码;
mysql数据库的密码存放在:mysql库中的user表中;
密码字段为:authentication_string
a、查看mysql数据库中mysql库user表中的user、host、authentication_string
——>select user,host,authentication_string from mysql.user;
如图所示:
b、修改mysql的登陆密码;
——>update mysql.user set authentication_string=password("luo123")
——>where user="root" and host="local";
注:这里一定要加条件,不然会把所有用户的密码都改掉;
c、刷新数据库权限;
——>flush privileges;
第五步、退出数据库重新进入验证密码;
第二种更改密码的方法:
alter user user() identified by "密码" ;
密码的长度与复杂度策略
validate_password_length=6
validate_password_policy=0
shwo variables like "%password%"
译为:查看密码password的变量值;
这种方式修改密码需要注释skip-grant-tables,否则会报错;