MySQL 암호 찾기

2998 단어

환경


centos 7.x MySQL 5.7.20

전제

  • 1.MySQL을 다시 시작할 수 있습니다
  • 2.서버에 로그인할 수 있습니다

  • 조작하다

  • 1.원본 암호
  • [root@1]# mysql -uroot -p12345
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 4
    Server version: 5.7.20-log MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2017, 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.
    
    (root@localhost) [(none)]>
    
    
  • 2.비밀번호를 잊어버렸다고 가정해 보세요
  • - 1.  my.cnf
    vim /etc/my.cnf //  
    [mysqld]
    skip-grant-tables //   my.cnf  
    
    - 2.  MySQL
    service mysqld restart //  
    Shutting down MySQL.. SUCCESS!
    Starting MySQL... SUCCESS!
    
  • 3.암호를 수정합니다
  • [root@1]# mysql //  , 
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 2
    Server version: 5.7.20-log MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2017, 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.
    
    (root@localhost) [(none)]> alter user 'root'@'localhost' identified by '123'; //   skip grant, 。
    ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
    
    (root@localhost) [(none)]>flush PRIVILEGES; //  
    Query OK, 0 rows affected (0.01 sec)
    
    (root@localhost) [(none)]>alter user 'root'@'localhost' identified by '123'; //  
    Query OK, 0 rows affected (0.00 sec)
    
    (root@localhost) [(none)]>flush tables; //  
    Query OK, 0 rows affected (0.00 sec)
    
    (root@localhost) [(none)]>quit //  
    Bye
    
  • 4.성공 현상
  • [root@1]# mysql //  ,skip grant  
    ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
    
    [root@1]# mysql -uroot -p123 //  , 
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 4
    Server version: 5.7.20-log MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2017, 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.
    
    (root@localhost) [(none)]>
    

    주의: 설정 파일의skipgrant 주석을 지우기

    좋은 웹페이지 즐겨찾기