【问题标题】:Mysql to find password is forgettenmysql找密码忘记了
【发布时间】:2016-02-05 11:03:42
【问题描述】:

我忘记了 MySql 的 root 密码。我怎样才能找到它?

如何备份数据库和导入新数据库?

我尝试在此文件中更改用户密码中的root密码和权限;

“c:/Program Data/MySql/MySql Server 5.6/data/mysql/user.frm”

enter image description here

【问题讨论】:

    标签: mysql passwords mysql-workbench


    【解决方案1】:

    Mysql更改忘记密码

    0) shut down service mysql56
    
    1) go to C:\ProgramData\MySQL\MySQL Server 5.6
     (note that ProgramData is a hidden folder)
    
    2) look for file my.ini, open it and add one line skip-grant-tables below [mysqld],
          save  [mysqld]
    
    skip-grant-tables
    3) start service mysql56
    
    4) by right, you can access the database, and use the query below to update the password
    
    update mysql.user set password=PASSWORD('NEW PASSWORD') where user='root';
    5) shun down the service again, remove the line skip-grant-tables save it, and start the service again. try to use the password you set to login.
    

    【讨论】:

      【解决方案2】:

      重置密码 请按照以下步骤操作(如果您真的忘记了密码会很有帮助,并且您可以随时尝试,即使您目前不在这种情况下):

      1. 停止mysql

        sudo /etc/init.d/mysql stop
        

      或其他发行版

          sudo /etc/init.d/mysqld stop
      
      1. 以安全模式启动 MySQL

        sudo mysqld_safe --skip-grant-tables &
        
      2. 使用 root 登录 MySQL

        mysql -uroot
        
      3. 选择要使用的 MySQL 数据库

        use mysql;
        
      4. 重设密码

        update user set password=PASSWORD("mynewpassword") where User='root';
        
      5. 刷新权限

        flush privileges;
        
      6. 重启服务器

        quit
        
      7. 停止并重新启动服务器

      ubuntu 和 debian

          sudo /etc/init.d/mysql stop
      

      ...

          sudo /etc/init.d/mysql start
      

      在 CentOS、Fedora 和 RHEL 上

          sudo /etc/init.d/mysqld stop
          ...
          sudo /etc/init.d/mysqld start
      
      1. 用新密码登录

        mysql -u root -p
        

      输入新密码并再次享受您的服务器,就像什么都没发生一样

      取自mysql-resetting-a-lost-mysql-root-password

      wiki 还解释了使用文本文件重置密码的其他方法。

      【讨论】: