您的位置首页生活百科

MySQL修改root账号密码的方法

MySQL修改root账号密码的方法

的有关信息介绍如下:

MySQL数据库商银城商术中如何修改root用户的密码呢?下面总结了修360问答改root用户密码的一些方法

1:使用setp选民下讨诗国师assword语句修改

mysql>selectuser();+----------------+|user()|+----------------+|root@localhost|+----------------+1rowinset(0.08sec)mysql>setpassword=password('123456');QueryOK,0rowsaffected(0.00sec)mysql>flushprivileges;QueryOK,0rowsaffected(0.00sec)mysql>exit

MySQL修改root账号密码的方法

2:更新mysql数据库的user表

mysql>usemysql;Readingta现bleinforma初胡发用tionforcompletionoftableandcolumnnamesYoucanturnoffthisfeaturetogetaquickerstartupwith-ADatabasechangedmysql>updateusersetpassword=PASSWORD('QwE1沿原所变万汽23')whereuser='root';QueryOK,4rowsaffected(0.03sec)Rowsmatched:4Changed:4Warnings:0mysql>flushprivileges;QueryOK,0rowsaffected(0.00se活并c)mysql>quit

MySQL修改root账号密码的方法

3:使用mysqladmin命令修改

命令一般为mysqladmin-uroot-p'oldpassword'passwordnewpass如下所示:

[root@DB-Server~]#mysqladmin-uroot-p'123456'石始执白password'Qwe123'Warning:Usingapasswordonthecommandlineinterfacecanbei甚鲜每晚副洋得食剂烈nsecure.

验证r题oot密码修改是否成功

[r离型整阳论款且乙oot@DB-Serve践派r~]#mysqladmin-uroot-p'12345够深他强孙看井告粒输排6'password'Qwe123'Warning:Usingapasswordonthecommandlinein超适毛永机免都队请尼粉terfacecanbeinsecure.

 

上面都是在知道root密码的情况下修改root密码,如果忘记了root密码,如何修改root的密码呢?

1:首先停掉MySQL服务

[root@DB-Server~]#servicemysqlstopS杀修节著校激五直huttingdownMySQL..[OK][root@DB-Server~]#

[root@DB-Server~]#/etc/rc.d/init.d/mysqlstopShuttingdownMySQL..[OK]

2:然后使用mysql整左械推d_safe命令启动mysql,更新root账号的密码

   --skip-grant-ta称盾反bles:不启动grant-tables(授权表),跳过权限控制。

   --skip-networking:跳过TCP/IP协议,只在本机访问(这个选项不是必须的。可以不用)是可以不用

[root@DB-Server~]#mysqld_safe--user=mysql--skip-grant-tables--skip-networking&[1]5145Youhavenewmailin/var/spool/mail/root[root@DB-Server~]#15070914:10:53mysqld_safeLoggingto'/var/lib/mysql/DB-Server.localdomain.err'.15070914:10:53mysqld_safeStartingmysqlddaemonwithdatabasesfrom/var/lib/mysql[root@DB-Server~]#mysql-urootmysqlReadingtableinformationforcompletionoftableandcolumnnamesYoucanturnoffthisfeaturetogetaquickerstartupwith-AWelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis1Serverversion:5.6.20-enterprise-commercial-advancedMySQLEnterpriseServer-AdvancedEdition(Commercial)Copyright(c)2000,2014,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.mysql>showdatabases;+--------------------+|Database|+--------------------+|information_schema||mysql||performance_schema||test|+--------------------+4rowsinset(0.00sec)mysql>usemysqlDatabasechangedmysql>UPDATEuserSETpassword=PASSWORD("Qwe123")WHEREuser='root';QueryOK,4rowsaffected(0.01sec)Rowsmatched:4Changed:4Warnings:0mysql>flushprivileges;QueryOK,0rowsaffected(0.00sec)mysql>exitBye

3:重新启动MySQL服务。

以上所述就是本文的全部内容了,希望大家能够喜欢