1. 检查my.cnf,看看有没有密码......靠这也算一条啊

2. 如果能够重启,
首先使用–skip-grant-tables参数重启,然后改密码,再去掉–skip-grant-tables参数重启, 注意–skip-grant-tables的安全问题http://code.openark.org/blog/mysql/dangers-of-skip-grant-tables, 根据火丁笔记http://huoding.com/2011/06/12/85,还需要加上--skip-networking

$ mysqld_safe --skip-grant-tables --skip-networking &
接着使用SQL重置密码后,记得去掉skip-networking,以正常方式重启MySQL服务:

$ /etc/init.d/mysqld restart
上面的方法需要重启两次服务,实际上还能更优雅一点,重启一次即可: 首先需要把用到的SQL语句保存到一个文本文件里(/path/to/init/file):

UPDATE mysql.user SET Password=PASSWORD('...') WHERE User='...' AND Host= '...';
FLUSH PRIVILEGES;
接着使用init-file参数启动MySQL服务,

$ /etc/init.d/mysql stop
$ mysqld_safe --init-file=/path/to/init/file &
此时,密码就已经重置了,最后别忘了删除文件内容,免得泄露密码。

3.on linux / unix ONLY

$ cd data/mysql
$ cp -rp user.MYD bck_user.MYD_`date +%Y%m%d`cp -rp user.MYD /tmp/user.MYD
$ vi /tmp/user.MYD #(edit the hashed passwords next to root*)cp -rp /tmp/user.MYD user.MYD
$ sudo kill -HUP `pidof mysqld`
4.using an init-file

4.这里还有个第四点 using an init-file, which leads to just one restart of the database instead of two. It also avoids the security issue involved with using skip-grant-tables.

5.如果你在MySQL里边,那么可选择的办法就太多了
参考 <http://www.cnblogs.com/rootq/archive/2009/05/13/1456335.html>

MySQL Root密码丢失解决方法总结的更多相关文章

  1. 忘记mysql root密码的解决方法

    一. MySQL密码的恢复方法一 有可能你的系统没有 safe_mysqld 程序(比如我现在用的 ubuntu操作系统, apt-get安装的mysql) , 下面方法可以恢复 1. 停止mysql ...

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

    Centos下忘记mysql的root密码的解决方法 一:(停掉正在运行的mysql) [root@NetDakVPS ~]# service mysql stop 二:使用 “--skip-gran ...

  3. 使用SKIP-GRANT-TABLES 解决 MYSQL ROOT密码丢失(转)

    B.5.3.2 How to Reset the Root Password If you have never assigned a root password for MySQL, the ser ...

  4. mysql忘记root密码的解决方法

    Windows下mysql忘记root密码的解决方法 1. 首先检查mysql服务是否启动,若已启动则先将其停止服务,可在开始菜单的运行,使用命令:net stop mysql 或者在windows任 ...

  5. MySQL初始化root密码以及root密码忘记解决方法

    一.MySQL初始化root密码 mysql默认root用户没有密码,输入mysql –u root 进入mysql 1.进入mysql数据库 use mysql; 2.初始化root密码 mysql ...

  6. Windows下mysql忘记密码的解决方法

    Windows下mysql忘记密码的解决方法 mysql5.0 http://www.jb51.net/article/21984.htm方法一: 1.在DOS窗口下输入 net stop mysql ...

  7. openSUSE Linux 忘记root密码的解决方法

    openSUSE Linux 忘记root密码的解决方法 : 对于大部分linux发行版本,忘记root密码的时候,是可以通过单用户模式来重设密码的. 如在redhat/fedora 下,可以通过在启 ...

  8. [转载]Ubuntu 14.04中root 密码忘记解决方法

      Ubuntu 14.04中root 密码忘记解决方法 方法一: 如果用户具有sudo权限,那么直接可以运行如下命令: #sudo su root #passwd #更改密码 或者直接运行sudo ...

  9. 【转】mysql忘记root密码的解决方法

    本文收集于本人的笔记本,由于找不到原文出处.在此省略,如哪位知道可以联系我加上. 方法一:在windows下:1.打开命令行(DOS)窗口,停止mysql服务: net stop mysql 2.在D ...

随机推荐

  1. HTTP错误类别

    http_status_bad_request (400) the request could not be processed by the server due to invalid syntax ...

  2. Tornado之实例和扩展

    1.Tornado文件的结构: 1.Controllers控制器 2.Models数据库操作 3.Views前端显示 2.样例 #!/usr/bin/env python # -*- coding: ...

  3. 通过openresty && tengine && nginx 动态添加资源到 html 页面

    1. 目标 不用修改后端代码,但是还需要进行js .css 等资源文件的加载 主要的场景是进行统计分析 2.技术实现 通过服务器扩展进行动态添加 iis 可以添加模块,nginx 可以使用  sub_ ...

  4. Thumbnailator 图像处理

    Create a thumbnail from an image file Thumbnails.of(new File("original.jpg")) .size(160, 1 ...

  5. Android中执行的错误:java.lang.UnsatisfiedLinkError: Couldn't load locSDK3: findLibrary returned null.

    今天在使用百度地图的时候执行发现报错: 明明已经增加了liblocSDK3.so.但总是无法定位.提示错误java.lang.UnsatisfiedLinkError: Couldn't load l ...

  6. 黄聪:免费C#反编译软件工具。Reflector已经out了,试试ILSpy吧

    转载自:http://www.cnblogs.com/JamesLi2015/archive/2011/09/08/2170519.html Reflector是.NET开发中必备的反编译工具.即使没 ...

  7. angula的factory service provider

    本人学了一段时间的angular的服务(factory.service.provider),有了自己的一些对于他们的见解,如果说的对,敬请赐教!!! 以后更新

  8. Docker学习总结(一)—— namespace,cgroup机制

    1.namespace: Linux Namespaces机制提供一种资源隔离方案.PID,IPC,Network等系统资源不再是全局性的,而是属于特定的Namespace.每个 Namespace里 ...

  9. Java web概述

    声明:为了使初学者能更好的了解java web,所以我整理了下资料,概述了web应用程序. 一.web概述 静态web资源:内容是静态的,不同的人在不同的时间来访问时都是相同的内容.HTML.CSS. ...

  10. MySQL性能测试工具之mysqlslap

    MySQL性能测试工具之mysqlslap [日期:2014-10-05] 来源:Linux社区  作者:tongcheng [字体:大 中 小]   --转自Linux社区:http://www.l ...