MySQL數據庫密碼忘記之後,可以進入linux下修改原始密碼,步驟爲下。
第一步:登陸服務器管理員權限。
第二步:進入MySQL數據配置文件
[root@VM_0_8_centos ~]# vi /etc/my.cnf
最後一行添加免密碼登陸:skip-grant-tables
:wq保存退出。
第三步:重啓
[root@VM_0_8_centos ~]# systemctl restart mysqld.service
檢查是否啓動成功:systemctl status mysqld.service
第四步:免密登陸數據庫
[root@VM_0_8_centos ~]# mysql -uroot -p
Enter password:
這裏回車就就可進入。
第五步:修改mysql密碼
選擇數據庫:use mysql;
5.7以上版本運行:update user set password= password("newPassword")where user='root';
5.7以下版本運行:update user set authentication_string= password("newPassword")where user='root';
第六步:退出exit、將第二步文件添加的 skip-grant-tables 取消
第七步:重啓重複第三步。修改完成,可密碼登陸成功。
面向開發過程,記錄學習之路。