码迷,mamicode.com
首页 > 数据库 > 详细

mysql 数据库忘记密码【转载】

时间:2014-09-12 13:38:43      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   使用   ar   数据   art   

在windows环境下

1.杀死所有的mysql进程

      a.通过dos命令:net start 与net stop mysql

      b.通过控制面板的服务

2.在dos的提示框内,将路径定位到mysql的安装目录下如:c:\mysql\bin

     在控制台输入:mysqld  --skip-grant-tables    //越过root权限

     回车后,没有任何显示,表示成功

3.重新打开一个dos提示框,在框内输入mysql -u root -p 进行无密码登陆

4.对mysql的密码进行修改

   输入如下命令

    >use mysql 

    >update user set password=password("new_pass") where user="root"; 

    >flush privileges; 

    也可以这样:mysqladmin -h hostname -u user password ‘new password‘‘。

    在载入权限`mysqladmin -h hostname flush-privileges‘ ,或者使用 SQL 命令`flush privileges‘。 

5.退出

   输入\q

6.重新进入以新修改的密码进入mysql



在linux环境下:

  1.终端输入 vi  /etc/my.cnf

     回车,进入修改,在[mysqld]段中加入

     skip-grant-tables保存退出

   2.重启mysql的服务

       service mysqld restart

   3.登录mysql

      终端输入:mysql回车登录

      进入mysql后,输入:

      use mysql;

      update user set password=password(‘new password‘) where user=‘root‘;

      flush privileges;

      quit;

      退出mysql

   4.再次进入vi  /etc/my.cnf

      修改回原来的状态,去掉skip-grant-tables,保存退出

   5.重启mysql服务

        service mysqld restart,用新密码登录

转载url:http://mrhouzhibin.blog.163.com/blog/static/1945962412011926112959446/

mysql 数据库忘记密码【转载】

标签:style   blog   http   color   os   使用   ar   数据   art   

原文地址:http://my.oschina.net/u/819305/blog/312745

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!