恢復Mysql數據庫root密碼
在管理數據庫工作中,如果忘記數據庫root將是十分災難的一件事情.所以如何在忘記root密碼的情況下恢復密碼呢?
- 停止Mysql服務程序
- 修改配置文件,跳過授權表
- 啓動Mysql服務程序
- 修改root密碼
- 驗證root密碼
1 停止mysql服務程序
systemctl stop mysqld
2 修改配置文件,跳過授權表
vim /etc/my.cnf
[mysql]
skip-grant-tables
:wq
3 啓動Mysql服務程序
systemctl restart mysql
4 修改root密碼
mysql
update mysql.user set authentication_string=password(“密碼”) where user=“root” and host=“localhost”;
flush privileges;
exit;
5 驗證root密碼
mysql -uroot -p"密碼"
重置Mysql數據庫root密碼
那麼在我們知道Mysql數據庫root密碼的情況下,如何重置root密碼呢?
在shell命令行修改登錄密碼
mysqladmin -uroot -p password “新密碼”
需要注意此時要驗證舊密碼
Enter Password:舊密碼
回車之後會有一個Warning提示,提示你在命令行輸入了明文密碼,不安全,不用理會.