場景說明
要連接到某服務的數據庫,但是忘記了root密碼,試了幾次都無法登陸
找回密碼步驟
1.在/etc/my.cnf [MySQLd] 配置部分添加"skip-grant-tables"
vim /etc/my.cnf
[mysqld]
skip-grant-tables
2.重啟mysql服務
systemctl restart mysqld
3.登入mysql
mysql -uroot -p123 #密碼隨便輸入都可以
4.刷新一下庫權限
mysql> flush privileges;
如果不執行這句話,會報以下錯誤! ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
5.新增一個遠程管理員賬號,然后退出數據庫
grant all privileges on *.* to 'admin'@'%' identified by 'foshan123' with grant option;
6.去除配置后重啟數據庫
(1)注釋/etc/my.cnf中skip-grant-tables
(2)執行systemctl restart mysqld命令重啟數據庫






