mysql版本爲5.7.22
1.修改my.cnf文件
添加一行
skip-grant-tables=1
保存退出。
2. 停掉mysql服務。
3. 運行登陸命令
mysql -u root
4. 修改密碼
mysql -u root;
update user set authentication_string = password('${yourPassword}'),password_last_changed=now() where user='root';
${yourPasswor}你的新密碼。
5. 刪除my.cnf裏的skip-grant-tables=1
6.重啓mysql
7.進入mysql重新修改密碼。
步驟見centos7.5下mysql5.7.22安裝,與裏面的密碼設置一樣即可。