mysql5.7版本忘記root賬號密碼需要重置密碼的處理過程
打開mysql配置文件(配置文件路徑可能不一樣)
vi /etc/my.cnf
在配置文件最后另起一行并添加以下內(nèi)容,保存退出
skip-grant-tables
重啟mysql服務(wù);
service mysqld restart
使用mysql命令,并回車
mysql
選中mysql表
use mysql;
查看用戶表
select host, user, authentication_string, plugin from user;
將root用戶的密碼置為空
update user set authentication_string='' where user='root';
退出mysql
exit
打開mysql配置文件(配置文件路徑可能不一樣)
vi /etc/my.cnf
刪除剛剛添加的那一行內(nèi)容,保存退出
skip-grant-tables
重啟mysql服務(wù);
service mysqld restart
使用root用戶進行登錄,因為上面設(shè)置了authentication_string為空,所以可以免密碼登錄;
mysql -uroot;
更新root用戶密碼為 AAbb123456789!! (5.7版本對密碼強度有要求,盡可能的設(shè)置為復(fù)雜一點),一般情況下root用戶只允許在localhost登陸
ALTER user 'root'@'localhost' IDENTIFIED BY 'AAbb123456789!!';