MySQL root 用戶密碼重置文章

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)閉。

2、以安全模式啟動(dòng)MySQL

Linux下,運(yùn)行 /usr/local/mysql/bin/mysqld_safe --skip-grant-tables &

Windows下,在命令行下運(yùn)行 X:/MySQL/bin/mysqld-nt.exe --skip-grant-tables

3、完成以后就可以不用密碼進(jìn)入MySQL了

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)入

4、更改MySQL數(shù)據(jù)庫(kù)密碼

>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>

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容