zoukankan      html  css  js  c++  java
  • MySQL Root密码丢失解决方法总结

    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>

  • 相关阅读:
    搜索引擎
    Mybatis springmvc面试题
    spring框架面试题
    数据库
    javaWEB面试题
    JavaWeb
    SpringCloud2
    网络
    比特币网络架构及节点发现分析
    Github推荐一个国内牛人开发的超轻量级通用人脸检测模型
  • 原文地址:https://www.cnblogs.com/buro79xxd/p/4128655.html
Copyright © 2011-2022 走看看