mysql数据库root密码丢失后的恢复方法

1、结束当前正在运行的mysql进程。
# killall mysqld

有时不行,仍然还有,则运行/etc/init.d/mysql stop

2、用mysql安全模式运行并跳过权限验证。
# /usr/bin/mysqld_safe –skip-grant-tables

或mysqld –skip-grant-tables &

3、以root身份登录mysql。
# mysql -u root
4. 修改root用户的密码;
mysql> update mysql.user set password=PASSWORD(‘新密码’) where User=’root';
mysql> flush privileges;
mysql> quit

Note:如果报错,乃是因为“‘”引号问题,不能复制粘帖,要打英文的单引号!

mysql> update mysql.user set password=PASSWORD(‘shenzy’) where User=’root’;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘��shenzy’) where User=’root’’ at line 1

 

5、结束mysql安全模式,用正常模式运行mysql。
# killall mysqld
# mysqld

Leave a Reply

  

  

  

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>