先貼出問題
屏幕快照 2018-03-04 下午1.08.02.png
網(wǎng)上找了很多方法训措,安全模式下重置mysql密碼鳖宾,反而更有效果。
按以下步驟操作:
1.進(jìn)入到/usr/local/mysql/support-file 這個目錄下顷帖,執(zhí)行命令:sudo ./mysql.server stop 命令美旧,或者在設(shè)置中關(guān)閉mysql服務(wù)。
2.然后再終端輸入:sudo mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
??:如果出現(xiàn) permission denied.需要我們添加權(quán)限贬墩。
執(zhí)行命令:sudo chown -R mysql /usr/local/mysql/data/
3.接著可以直接輸入:mysql -u root 進(jìn)入mysql榴嗅。
或者重新打開一個終端窗口,輸入:mysql -u root mysql
4.進(jìn)入mysql>
輸入以下命令:update mysql.user set authentication_string=password('新密碼') where user='root' and host='127.0.0.1' or host='localhost';
5.接著輸入:flush privileges; (這一步很關(guān)鍵 )
6.退出:quit;
這個時候陶舞,就可以打開終端嗽测,進(jìn)行登錄,輸入命令:mysql -uroot -p
此時輸入新設(shè)置的密碼:admin (這是我的密碼)
進(jìn)入我們期待的頁面肿孵,如下:
屏幕快照 2018-03-14 上午10.36.45.png
本電腦mysql的版本是5.7,在此之前的版本唠粥,只需修改設(shè)置密碼的命令行,改為:
mysql> update user set password=password('新密碼') where user='root';
其它命令照舊停做。
2.ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
解決方法:
1.mysql>set password=password("123456"); 回車執(zhí)行
2.flush privileges;
就可以了厅贪。截圖如下:
屏幕快照 2018-04-10 下午11.25.37.png