亚洲女同成aV人片在线观看|亚洲www啪成人一区二区麻豆|亚洲国产中日韩精品综合|亚洲国产成人精品一级片|亚洲无码在线视频免费

快速導航×

當前位置: 首頁(yè) > 新聞中心
MySQL修改密碼的幾種方式發(fā)表于: 2026-05-04 22:19:07

這篇文章主要介紹了MySQL??修改密碼的改密幾種方式,幫助大家更好的種方理解和使用MySQL,感興趣的改密朋友可以了解下

前言:

在日常使用數據庫的過(guò)程中,難免會(huì )??遇到需要修改賬號密碼的種方情景,ヾ(?■_■)ノ比如密碼太簡(jiǎn)單需要修改、改密密碼過(guò)(??ヮ?)?*:???期需要修改、種(zhong)方忘記密(???)碼需要修改等。改密本篇文章將會(huì )介紹需要修改密碼的種方場(chǎng)景及修改密碼的幾種?方式。

1.忘記 root 密碼

忘記 root 密碼的改密場(chǎng)景還是比較常(chang)見(jiàn)的,特別是種方??自己搭的測試環(huán)( ?° ?? ?°)境經(jīng)過(guò)好久沒(méi)用過(guò)時(shí),很容易記不得當時(shí)設置的改密密碼。這個(gè)時(shí)候一般常用的種方方法是跳過(guò)權限驗證,然后更(??-)?改 root 密碼,改密之后再啟用權限驗證。種方以 My??SQL 5.7 版本為例簡(jiǎn)單講下主要過(guò)程:

首先修改配置文件,??改密???在[mysqld]部分加上一句:skip-grant-tables ,加上此參數的目的是跳過(guò)權限驗證。然后重啟數據庫,數據庫再次啟動(dòng)后,我們就可以不用密碼直接登??錄數據庫修改密碼了。

#skip-grant-tables模式下修改root密碼
[root@hos??t~]#mysql
WelcometotheMySQLmonitor.(╬?益?)Commandsendwith;or\g.
YourMySQLconnectionidis16
Serverversion:5.(′?ω?`)7.23-logMySQLCommunity( ?▽?)Server(GPL)

Copyright(c)2000,2018,Oracleand/oritsaffiliates.Allrightsreserved.

OracleisaregisteredtrademarkofOracleCorporationand/orits
affiliates.Othernamesmaybetrad??emarksoftheirrespective
owners.ヽ(′ー`)ノ

Type'help;'or'\h'forhelp.Type'\c'toclearthecヾ(^-^)ノurrentinputstヾ(′▽?zhuān)??atement.

mysql>updatemysql.usersetauthenticatio??n_string=password('xxxxxx??')whereuser='root'ヽ(′ー`)ノand(′_`)host='localhost';
QueryOK,0rowsaffected,1warning(0.00sec)
Rowsmatched:1C??hanged:0Warnings:1

mysql>flushprivileges;
QueryOK,0rowsaffected(0.01sec)

修改完 root 密碼后,再次去除 skip-grant-tables 參數,然后重啟下數據庫即可。

2.幾種修改密碼的方法

除去忘記密碼,可能還有(?⊿?)其他情景需要修改密碼,這時(shí)候就可以采取普通方式修改密碼了。還是以 MySQL 5.7 版本為例,介紹幾種常用的修改密碼的方法。

使用?? alter user 修改

比如如果想更改 testuser 賬號的密碼,我們可以使用 roo??t 賬號登錄,然后執行 alter user 命令更改 testuser 賬號的密碼。

mysql>alteruser??'testuser'@'%'identifiedby'Pa??ssword1';
QueryOK,0rowsaffected(0.01sec)

mysql>??flushprivileges;
QueryOK,0rowsaffected(0.00sec)

使用 SET PASSWORD 命令

使用 SET PASSWORD 修改(gai)密碼命令格式為 SET PASSWORD FOR 'username'@'host' = PASSWORD('newpass'); 同樣(yang)是使用 root 賬號可修改其他賬號的密碼。

mysql>SETPASSWORDFOR'test??user'@'%'=PASSWORD('Password2');
QueryOK,0rowsaf(⊙_⊙)fec(′_ゝ`)ted,1warning(0.00sec)

mysql>flushprivi(′Д` )leges;
QueryOK,0rowsaffected(0.00sec)

使用 mysqladmin 修改密??碼

使用 mysqladmin 命令修改賬號密碼格式為 mysqladmin -u用戶(hù)名 -p舊密碼 password 新密碼

[(′-ι_-`)roo??t@host~]#mysqladmin-utestuser-pPassword2passwordPassword3
mysqladmin:[Warning]Usingapasswordonthecommandlineinterfacecanbeinsecure.
Warning:Sincepasswo( ?▽?)rdwillbesenttoserverinplaintext,usesslconn??ectiontoensurepasswordsafety.
[root@host~]#mys??ql-ute(′ω`*)stuser-pPassword3
mysql:[Warning]Usingapasswordonthecommandlineinterfacecanbeinsecure.
Welcometoth??ヽ(′▽?zhuān)?ノeMySQLmo??nitor.Commandsendwith;or\g.
YourMySQLconnectionidis2388
Serverversion:5.??7.┐(′д`)┌23-logMySQLCo(′;ω;`)mmunityServer(GPL)

Copyrigh??t(c)2000,2018,Oracleand/oritsaffiliates.Allrightsreserved.

OracleisaregisteredtrademarkofOracleCorporationand/orits
affiliates.Othernamesmaybe??trademarksoftheirrespective
owners.

Type'help;'or'\h'(′ω`)forhelp.Type'\c'toclearthecurrentinputsta??tement.

mysql&??gt;

直接 update user 表

其(qi)實(shí) MyS??QL 所以的賬號信息都存儲在 mysql.user 表里面,我們也可以直接通過(guò) update user 表來(lái)修改密碼。

#5.7及之后版本
mysql>updatemysql.usersetauthentication_string=password('Password4')whereuser='testuser'andhost='%';
Qu??eryOK,1rowaffected(╯°□°)╯︵ ┻━┻,1warning(0.06sec)
Rowsmatched:1Changed:1Warnings:1

mysql>flushprivileges;
QueryOK,0rowsaffected(0.01sec)

#ヽ(′▽?zhuān)?ノ5.6及之前版本
updatemヾ(′?`)?ysql.usersetpassword=password('新密碼')whereus??er='用戶(hù)名'andhost='host';

3.(╯°□°)╯設置 login-path 本地快捷登陸

為了防止密碼暴露及忘記密碼,我們還可以設置 login-path 來(lái)實(shí)現在本地不輸密碼快捷登錄。

login-path 是 MySQL(′;д;`) 5.6 開(kāi)始支持的新特性。通過(guò)借助 mysql_config(′_ゝ`)_editor 工具將登陸 MySQL 服務(wù)的認證信息加密保存在 .mylogin.cnf 文件(默認位于??用戶(hù)主目錄)。MySQL 客戶(hù)端工具可通過(guò)讀取該加密文件連接 MySQL ,實(shí)現快ヾ(′▽?zhuān)??捷登錄。

假ヽ(′▽?zhuān)?ノ設我們想配置 root 賬號在本地快捷登錄,可(ke)以這么做:

#執行回車(chē)后需要輸入一次root密碼
[root@host~]#mysql_config_editorset--lo┐(′?`)┌gin-path=root-uroヽ(′ー`)ノot-hlocalhost-p-P3306
Enterpassw??ord:

#配置完成后可以使用login-path登錄
[root@host~]#mysql--login-path=root
WelcometotheMySQLmonitor.Commandsendwith;or\g.
YourMySQLconnectionidis2919
Serverversion:5.7.23-logMySQLCommunityServer(GPL)

Copyright(c)2000,2018,Oracleand/oritsaffiliates.Allrightsreserved.

Oracleisaregistere??dtrademarkofOracleCorporationand/orits
affiliates.Othernamesmaybetra??demarksoftheirrespective
ow┐(′д`)┌ners.

Type'help;'or'\h'forhelp??.Type'\c'toclearthecurrentinputstate(′_ゝ`)ment.

mysql>

總結:

本篇文章主要介紹了(′?`*)修改數據庫賬號密碼的幾種方法,基本涵蓋了所有的場(chǎng)景。這里也提醒下各位,數據庫賬號最好限制ip段登錄,密碼盡量復雜些,最好能夠定期修改,特別是重要的環(huán)境不能有半點(diǎn)馬虎。年底了,安全才(′▽?zhuān)?)是王道(dao)。

以上就是MySQL修改密碼的幾種方式的詳細內容,更多關(guān)于MySQL修改密碼的資料請關(guān)注腳本之家其它相關(guān)文章!

來(lái)源:腳本之家

鏈接:https://www.jb51.net/article/202370.ht(╯°□°)╯︵ ┻━┻m

亚洲女同成aV人片在线观看|亚洲www啪成人一区二区麻豆|亚洲国产中日韩精品综合|亚洲国产成人精品一级片|亚洲无码在线视频免费 阿巴嘎旗| 台东县| 台东市| 元谋县| 广河县| 信宜市| 余江县| 彭水| 石门县| 佳木斯市| 瑞丽市| 临沭县| 宁夏| 芷江| 濉溪县| 九龙县| 景东| 五寨县| 东乡县| 佛冈县| 南涧| 环江| 长白| 台湾省| 凤城市| 平阳县| 永寿县| 舟曲县| 镇坪县| 绥德县| 毕节市| 临高县| 兴仁县| 凤凰县| 原阳县| 玉山县| 包头市| 玉门市| 湛江市| 宝清县| 吕梁市| http://444 http://444 http://444 http://444 http://444 http://444