1旗扑、用命令編輯/etc/my.cnf配置文件,即:vim /etc/my.cnf
2.在[mysqld]下添加skip-grant-tables慈省,然后保存并退出
image.png
修改密碼UPDATE mysql.user SET Password=PASSWORD('新密碼') where USER='root';
如果是5.7版本運(yùn)行update mysql.user set authentication_string=password('root') where user='root' ;
即可
因?yàn)?.7把密碼地段換成了authentication_string
刷新權(quán)限flush privileges;
最后把/etc/my.cnf
中的skip-grant-tables
注釋掉臀防,然后重啟mysql,即:service mysqld restart
image.png
重新登陸MySQL
image.png