第一步、暫停mysql服務(wù);
? ? systemctl? stop? mysqld
第二步、修改mysql的配置文件/etc/my.cnf
? ? vim? /etc/my.cnf? ? ##在文件添加一行;
? ? skip-grant-tables? ##譯為:跳過mysql數(shù)據(jù)庫的授權(quán)表;
? ? #validate_password_length=6? ? ##注釋掉驗(yàn)證密碼的長度
? ? #validate_password_policy=0? ? ##注釋掉驗(yàn)證密碼的策略
第三步、保存配置文件,重新啟動服務(wù);
? ? systemctl? restart? mysqld
第四步、mysql? 直接進(jìn)入數(shù)據(jù)庫修改登陸密碼;
? ? mysql數(shù)據(jù)庫的密碼存放在:mysql庫中的user表中;
? ? 密碼字段為:authentication_string
a、查看mysql數(shù)據(jù)庫中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、刷新數(shù)據(jù)庫權(quán)限;
? ? ? ——>flush? privileges;
第五步、退出數(shù)據(jù)庫重新進(jìn)入驗(yàn)證密碼;
第二種更改密碼的方法:
alter? user? user()? identified? by? "密碼"? ;
?
密碼的長度與復(fù)雜度策略
validate_password_length=6
validate_password_policy=0
shwo? variables like "%password%"
譯為:查看密碼password的變量值;
這種方式修改密碼需要注釋skip-grant-tables,否則會報(bào)錯(cuò);