1、首先停止正在運(yùn)行的MySQL進(jìn)程
Linux下,運(yùn)行 killall -TERM MySQLd
Windows下,如果寫成服務(wù)的 可以運(yùn)行:net stop MySQL,如未加載為服務(wù),可直接在進(jìn)程管理器中進(jìn)行關(guān)閉。
Linux下,運(yùn)行 /usr/local/mysql/bin/mysqld_safe --skip-grant-tables &
Windows下,在命令行下運(yùn)行 X:/MySQL/bin/mysqld-nt.exe --skip-grant-tables
Linux下,運(yùn)行 /usr/local/mysql/bin/mysql -u root -p 進(jìn)入
Windows下,運(yùn)行 X:/MySQL/bin/mysql -u root -p 進(jìn)入
>use?mysql
>>update user set password=password("root") where user="root";
>flush privileges;
#1.停止mysql數(shù)據(jù)庫(kù)
/etc/init.d/mysqldstop
#2.執(zhí)行如下命令
mysqld_safe?--user=mysql?--skip-grant-tables?--skip-networking?&
#3.使用root登錄mysql數(shù)據(jù)庫(kù)
mysql?-u?root?mysql
#4.更新root密碼
mysql>?UPDATE?user?SET?Password=PASSWORD('newpassword')?where?USER='root';
#最新版MySQL請(qǐng)采用如下SQL:
mysql>?UPDATE?user?SET?authentication_string=PASSWORD('newpassword')?where?USER='root';
#5.刷新權(quán)限
mysql>?FLUSH?PRIVILEGES;
#6.退出mysql
mysql>?quit
#7.重啟mysql
/etc/init.d/mysqldrestart
#8.使用root用戶重新登錄mysql
mysql?-uroot?-p
Enter?password:?<輸入新設(shè)的密碼newpassword>