zoukankan      html  css  js  c++  java
  • MySQL密码修改(四)

    一、修改破解MySQL密码

      1.1:修改密码

    在知道原始密码的情况下
    [root@web1 ~]# mysqladmin -uroot -p -S /home/mysql/3307/mysql.sock password "brian123"   # 要修改的密码
    Enter password:123456
    
    # 测试
    [root@web1 ~]# mysql -uroot -p -S /home/mysql/3307/mysql.sock
    Enter password:123456
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
    
    [root@web1 ~]# mysql -uroot -p -S /home/mysql/3307/mysql.sock
    Enter password:brian123
    [root@web1 ~]# mysql -uroot -p -S /home/mysql/3307/mysql.sock
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 6
    Server version: 5.7.23 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    
    
    
    # 登录数据库修改密码
    update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';
    alter user 'root'@'localhost' identified by '123'; 
    set password for 'root'@'localhost'=password('123');
    # 一定记得刷新权限,不然不生效
    flush privileges;

      1.2:破解密码

    # 数据库密码忘记了
    PS:在单实例的情况下我们是可以停掉数据库的,但是在多实例的情况下没有密码是停不了的,只能用kill 来停的
    
    # 使用kill停止不记得密码的数据库
    [root@web1 ~]# ps aux | grep 3306 | awk '{print $2}' |xargs kill
    
    # 使用mysqld_safe 加参数绕过认证
    PS: 我用的是多实例的,根据实际情况修改下面的路径就行
    [root@web1 ~]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/home/mysql/3306/my.cnf --user=mysql --skip-grant-tables &
    [root@web1 ~]# netstat -lntup | grep 3306
    tcp6       0      0 :::3306                 :::*                    LISTEN      57475/mysqld
    
    # 现在就是没有密码可以登录了
    [root@web1 ~]# mysql -uroot -p -S /home/mysql/3306/mysql.sock
    Enter password:                                                     # 这一步直接回车
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2
    Server version: 5.7.23 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    
    # 进来以后再修改密码
    mysql> update mysql.user set authentication_string=password('123qwe') where user='root' and Host = 'localhost';
    Query OK, 1 row affected, 1 warning (0.00 sec)
    Rows matched: 1  Changed: 1  Warnings: 1
    
    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    
    mysql>
    
    # 停掉MySQL重新启动 这次不用指定--skip-grant-tables参数了
    [root@web1 ~]# ps aux | grep 3306 | awk '{print $2}' |xargs kill
    [root@web1 ~]# /usr/local/mysql/bin/mysqld_safe --defaults-file=/home/mysql/3306/my.cnf --user=mysql &
    [root@web1 ~]# mysql -uroot -p -S /home/mysql/3306/mysql.sock
    Enter password: 123qwe
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2
    Server version: 5.7.23 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    

      

    作者:朱敬志

    -------------------------------------------

    个性签名:在逆境中要看到生活的美,在希望中别忘记不断奋斗

    如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!

    万水千山总是情,打赏一分行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主,哈哈哈(っ•̀ω•́)っ✎⁾⁾!

    支付宝 微信

    也可以关注我的微信公众号,不定时更新技术文章(kubernetes,Devops,Python)等

    微信公众号
  • 相关阅读:
    20191331 《信息安全专业导论》第12周学习总结
    20191331 《信息安全专业导论》第11周学习总结
    20191331 《信息安全专业导论》第10周学习总结
    20191331 《信息安全专业导论》第9周学习总结
    20191331《信息安全专业导论》第7周学习总结
    20191331 《信息安全专业导论》第6周学习总结
    20191331《信息安全专业导论》第5周学习总结
    20191331 《信息安全专业导论》第4周学习总结
    2013暑假心愿单
    怎样产生一个app的idea?
  • 原文地址:https://www.cnblogs.com/zhujingzhi/p/9609904.html
Copyright © 2011-2022 走看看