天天看点

Centos下忘记mysql的root密码的解决方法

二:使用

<code>[root@NetDakVPS ~]# mysqld_safe --skip-grant-tables &amp;</code>

<code></code>

<code>[1] 23810</code>

<code>Starting mysqld daemon with databases from /var/lib/mysql</code>

三:用root帐号登录mysql

<code>[root@NetDakVPS ~]# mysql -u root</code>

<code>Welcome to the MySQL monitor. Commands end with ; or \g.</code>

<code>Your MySQL connection id is 1</code>

<code>Server version: 5.0.77 Source distributionType 'help;' or '\h' for help. Type '\c' to clear the buffer.</code>

四:改变用户数据库

<code>mysql&gt; use mysql</code>

<code>Reading table information for completion of table and column names</code>

<code>You can turn off this feature to get a quicker startup with -ADatabase changed</code>

<code>mysql&gt; update user set password=password('netdak') where user='root';</code>

<code>Query OK, 1 row affected (0.04 sec)</code>

<code>Rows matched: 1 Changed: 1 Warnings: 0</code>

六:刷新权限表

<code>mysql&gt; flush privileges;</code>

<code>Query OK, 0 rows affected (0.00 sec)</code>

七:退出mysql

<code>mysql&gt; quit</code>

<code>Bye</code>

八:对mysql进行重启

<code>[root@NetDakVPS ~]# service mysql restart;</code>

<code>STOPPING server from pid file /var/run/mysqld/mysqld.pid</code>

<code>100421 13:44:03 mysqld endedStopping MySQL: [ OK ]</code>

<code>Starting MySQL: [ OK ]</code>

<code>[1]+ Done mysqld_safe --skip-grant-tables</code>

<code>[root@NetDakVPS ~]# mysql -u root -p</code>

<code>Enter password: netdak</code>

<code>Your MySQL connection id is 2</code>

<code>Server version: 5.0.77 Source distributionType 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql&gt; quit</code>

十、重新执行修改密码

SET PASSWORD = PASSWORD('123456');

注:第十步不一定需要,但是 MySql5.6操作时可能会报错:You must SET PASSWORD before executing this statement.