linux環境下忘記mysql密碼
阿新 • • 發佈:2021-10-15
1. 檢查mysql
服務是否啟動,如果啟動,關閉mysql
服務
執行命令:
如果開著就執行關閉的命令:service mysqld stop
2.修改mysql的配置檔案my.conf
一般在/etc目錄下,執行命令:vi /etc/my.cnf,編輯檔案
在檔案的[mysqld]標籤下新增一句:
skip-grant-tables
然後wq!儲存退出。
3.重啟資料庫
執行命令:service mysqld start
4.重啟資料庫
執行命令:service mysqld start
5.進入到mysql資料庫
執行命令:mysql -u root
6.進入到mysql資料庫
執行命令:mysql -u root
7.修改密碼
執行語句:use mysql;
繼續執行語句:update mysql.user set authentication_string=password('root_password') where user='root';
root_password
替換成你想要的密碼
8.把步驟2加的東西刪除掉,在重啟伺服器,就可以使用剛才修改的密碼登入進伺服器了。
mysql -u root -p
到這一步已經全部結束。
轉自:cnblogs.com/black-fact/p/11613361.html