首页 > 数据库技术 > 详细

忘记mysql root密码的解决方法

时间:2014-09-15 21:06:59      阅读:361      评论:0      收藏:0      [点我收藏+]

一. MySQL密码的恢复方法一

有可能你的系统没有 safe_mysqld 程序(比如我现在用的 ubuntu操作系统, apt-get安装的mysql) ,

下面方法可以恢复 1. 停止mysqld; /etc/init.d/mysql stop (您可能有其它的方法,总之停止mysqld的运行就可以了)

2. 用以下命令启动MySQL,以不检查权限的方式启动;

mysqld --skip-grant-tables & 或 mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

3. 然后用空密码方式使用root用户登录 MySQL; mysql -u root mysql

4. 修改root用户的密码;

mysql> update mysql.user set password=PASSWORD(‘newpassword‘) where User=‘root‘ and host=‘root‘ or host=‘locahost‘;

mysql> flush privileges;

mysql> quit 重新启动

MySQL /etc/init.d/mysql restart

#mysql -uroot -p

 

就可以使用新密码 newpassword 登录了。

二. MySQL密码的恢复方法之二 如果忘记了MySQL的root密码,可以用以下方法重新设置:

1. KILL掉系统里的MySQL进程; killall -TERM mysqld

2. 用以下命令启动MySQL,以不检查权限的方式启动; safe_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 重新启动MySQL,

#mysql -uroot -p

就可以使用新密码登录了。

 

忘记mysql root密码的解决方法

原文:http://www.cnblogs.com/GeneralXU/p/3973497.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!