解決linux下mysql忘記密碼的情況
阿新 • • 發佈:2019-02-07
linux下mysql-5.6忘記root密碼,重置root密碼詳細過程
1、首先停止mysql服務程序:
service mysqld stop
2、然後編輯mysql的配置檔案my.cnf
vim /etc/my.cnf
在my.cnf檔案末尾加:skip-grant-tables後儲存退出//就可以直接登入mysql了
3、啟動mysql:
service mysqld start
4、在linux命令列介面下輸入:mysql
直接進入mysql資料庫
5、在mysql命令列輸入:use mysql//使用資料庫mysql
6、然後輸入
update user set password=password("123456") where user="root";//這個可能不行因為版本可能不同
或update user set authentication_string=password('123456') where user="root";
7、修改成功後退出mysql在命令列輸入:exit
8、再次停止mysql:service mysqld stop
9、然後註釋掉在my.cnf中加入的那行:在行前面加#然後儲存退出(不註釋也可以刪除)
10、再次啟動mysql:service mysqld restart
11、然後輸入密碼登入:mysql -uroot -p123456
12、進去後可能要重新設定密碼:
如出現這個:ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
就在mysql命令列輸入:set password=password("你的設定的密碼");
密碼需要數字+字母+長度大於6吧
可能密碼強度要求較強請點選下面的連結修改