最近弄了個阿裡雲,選的CentOS7系統,裝上MySQL之後,重置了密碼,兩天沒用密碼就忘記了。
于是搜尋了一下相關解決方法
參考
https://blog.csdn.net/sikefeng/article/details/79597230
- 第一步
vim /etc/my.cnf
加入 skip-grant-tables
- 第二步
重新開機MySQL
systemctl restart mysqld
- 第三步
可以直接進入MySQL,不用輸入密碼
mysql -uroot -p
- 第四 步
修改密碼
update mysql.user set authentication_string=password("你的密碼") where user="root";
- 第五 步
退出資料庫,重新編輯my.cnf檔案,去除 skip-grant-tables
vim /etc/my.cnf
- 第六步
重新開機資料庫,否則依然是無密碼進入模式。