#1.中止mysql數據庫 /etc/init.d/mysqld stop #2.執行以下命令 mysqld_safe --user=mysql --skip-grant-tables --skip-networking & #3.使用root登陸mysql數據庫 mysql -u root mysql #4.更新root密碼 mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root'; #最新版MySQL請採用以下SQL: mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root'; #5.刷新權限 mysql> FLUSH PRIVILEGES; #6.退出mysql mysql> quit #7.重啓mysql /etc/init.d/mysqld restart #8.使用root用戶從新登陸mysql mysql -uroot -p Enter password: <輸入新設的密碼newpassword>
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------mysql
以安全模式啓動mysql,能夠直接以root身份登陸,而後重設密碼。下面是具體步驟sql
1.停掉在運行的MySQL服務:數據庫
service mysqld stop
2.安全模式啓動mysql:安全
sudo mysqld_safe --skip-grant-tables --skip-networking &
3.直接用root登陸,無需密碼:ui
mysql -uroot -p
4.重設密碼:spa
update usersetauthentication_string=password('password') where user='root'; >> mysql5.6及如下
update user set authentication_string=password('password') where user='root'; >>mysql5.7+
5.刷新並重啓.net
flush privileges;
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------rest
以root用戶登陸,命令:mysql -uroot -p 回車 輸入密碼; mysql>use mysql; mysql>UPDATE user SET password=PASSWORD('輸入新密碼') WHERE user='root'; mysql>FLUSH PRIVILEGES;