zoukankan      html  css  js  c++  java
  • MySQL数据库管理员密码忘记如何修改?

    系统环境:centos7

    数据库版本:mysql  Ver 14.14 Distrib 5.7.29, for linux-glibc2.12 (x86_64) using  EditLine wrapper

    一:首先要关闭数据库,以什么方式启动的数据库就要以什么方式结束数据库

    1 [root@db01 ~]#systemctl stop mysql
    2 [root@db01 ~]#ss -ntl
    3 State       Recv-Q Send-Q               Local Address:Port                              Peer Address:Port              
    4 LISTEN      0      128                              *:22                                           *:*                  
    5 LISTEN      0      128                           [::]:22                                        [::]:* 

    :在命令行界面执行,如下命令,执行完成后,数据库root账户的密码就清空了

    [root@db01 ~]#mysqld_safe --skip-grant-tables --skip-networking &
    [1] 15143
    [root@db01 ~]#2020-12-14T12:13:17.814024Z mysqld_safe Logging to '/data/mysql/data/db01.err'.
    2020-12-14T12:13:17.843723Z mysqld_safe Starting mysqld daemon with databases from /data/mysql/data

    三: 登录数据库,这个时候数据库没有密码的,如下

    [root@db01 ~]#mysql
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 2
    Server version: 5.7.29 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2020, 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> alter user root@localhost identified by '123456';
    ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

    在执行上述语句后,mysql会报错,继续执行如下语句,如下

    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)

    再一次执行修改密码的命令,如下,

    mysql> alter user root@localhost identified by '123456';
    Query OK, 0 rows affected (0.00 sec)

      出现如上信息,说明数据库密码修改成功。

    五:停止数据库的进程并登录验证数据库

     停止数据库的相关进程

    pkill mysqld

    数据库进程结束后,马上要启动数据库
    systemctl start mysqld
    [root@db01 ~]#mysql -uroot -p123456
    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 3
    Server version: 5.7.29 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2020, 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> 

      由以上信息可知,数据库登录成功

      

  • 相关阅读:
    QT编译时 cc1plus进程占用大量内存卡死问题解决
    python import cv2 出错:cv2.x86_64-linux-gnu.so: undefined symbol
    python ImportError: No module named builtins
    OSError: libcudart.so.7.5: cannot open shared object file: No such file or directory
    二维数组和二级指针(转)
    C/C++中无条件花括号的妙用
    C语言中do...while(0)的妙用(转载)
    卸载 ibus 使Ubuntu16.04任务栏与启动器消失 问题解决
    关于Qt creator 无法使用fcitx输入中文的问题折腾
    QT error: cannot find -lGL
  • 原文地址:https://www.cnblogs.com/molson/p/14132583.html
Copyright © 2011-2022 走看看