mysql中如何重置数据库密码?

    作者:课课家教育更新于: 2016-03-15 11:19:24

      MySQL密码重置,怎么办?忘记密码人之常情,那么我们该怎么办呢?密码重置分为两种,一种忘记了密码,一种记得密码。

    mysql中如何重置数据库密码?_数据库_数据库密码重置_课课家

      如果知道密码,则通过以下方式修改;

      gaurav@gaurav:~$mysql--user=root--passmysql

      Enterpassword:

      mysql>updateusersetPassword=PASSWORD('new-password-here')WHEREUser='root';

      QueryOK,2rowsaffected(0.04sec)

      Rowsmatched:2Changed:2Warnings:0

      mysql>flushprivileges;

      QueryOK,0rowsaffected(0.02sec)

      mysql>exit

      Bye

      如果忘记密码,则先停止mysql,然后加上参数skip-grant-tables重新启动mysqlserver

      root@gaurav:~#/etc/init.d/mysqlstop

      Nowyoushouldstartupthedatabaseinthebackground,viathemysqld_safecommand:

      root@gaurav:~#/usr/bin/mysqld_safe--skip-grant-tables&

      [1]4271

      Startingmysqlddaemonwithdatabasesfrom/var/lib/mysql

      mysqld_safe[6763]:started

      然后登陆mysql,修改密码

      root@gaurav:~$mysql--user=rootmysql

      Enterpassword:

      mysql>updateusersetPassword=PASSWORD('new-password-here')WHEREUser='root';

      QueryOK,2rowsaffected(0.04sec)

      Rowsmatched:2Changed:2Warnings:0

      mysql>flushprivileges;

      QueryOK,0rowsaffected(0.02sec)

      mysql>exit

      Bye

      最后重启mysqlserver就可以了。

      root@gaurav:~#/etc/init.d/mysqlstart

      StartingMySQLdatabaseserver:mysqld.

      Checkingforcorrupt,notcleanlyclosedandupgradeneedingtables..

      用新密码登陆验证下

      root@gaurav:~#mysql--user=root--pass=new-password-here

      WelcometotheMySQLmonitor.Commandsendwith;or\\g.

      YourMySQLconnectionidis5toserverversion:5.0.24a-Debian_4-log

      Type'help;'or'\\h'forhelp.Type'\\c'toclearthebuffer.

      mysql>exit

      Bye

课课家教育

未登录