数据库(mysql)忘记密码解决办法

步骤一:先停止数据库服务

[root@GGB ~]# systemctl  stop   mysql.service 
[root@GGB ~]# systemctl  status  mysql.service 
● mysql.service - MySQL Server
   Loaded: loaded (/etc/systemd/system/mysql.service; enabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since 五 2024-07-12 01:03:45 CST; 1s ago
  Process: 3738 ExecStop=/usr/local/mysql/bin/mysqladmin shutdown (code=exited, status=1/FAILURE)
  Process: 2951 ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/3306/data (code=exited, status=0/SUCCESS)
 Main PID: 2951 (code=exited, status=0/SUCCESS)

步骤二:采用安全模式启动数据库(空密码方式进入数据库) 
 

#mysqld_safe  一个命令
#--skip-grant-tables   Start without grant tables. This gives all users FULL  两个参数
#                      数据库服务启动时,不加载授权表(没有保安)
#--skip-networking     Don't allow connection with TCP/IP
                      关闭远程连接端口
mysqld_safe --skip-grant-tables  --skip-networking   &



[root@GGB ~] 
[root@GGB ~]  mysqld_safe --skip-grant-tables --skip-networking &
[1] 4642
[root@GGB ~]  2024-07-11T17:15:00.581337Z mysqld_safe Logging to '/data/3306/data/GGB.err'.
2024-07-11T17:15:00.600168Z mysqld_safe Starting mysqld daemon with databases from /data/3306/data

[root@GGB ~]  
[root@GGB ~]  ps -ef | grep mysql
root       4642   2019  0 01:14 pts/0    00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --skip-grant-tables --skip-networking
mysql      4798   4642  3 01:14 pts/0    00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/3306/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --skip-grant-tables --skip-networking --log-error=GGB.err --pid-file=GGB.pid --socket=/tmp/mysql.sock
root       4840   2019  0 01:15 pts/0    00:00:00 grep --color=auto mysql
[root@GGB ~]# 

步骤三:登录数据库设置数据库密码信息

[root@GGB ~]  mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.26 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> flush privileges;
Query OK, 0 rows affected (0.01 sec)

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

mysql> 

步骤四:重启数据库服务

#先pkiil 掉之前后台启动的数据库
[root@GGB ~] pkill mysql
[root@GGB ~] 
[root@GGB ~] 2024-07-11T17:19:26.708758Z mysqld_safe mysqld from pid file /data/3306/data/GGB.pid ended

[1]+  完成                  mysqld_safe --skip-grant-tables --skip-networking
[root@GGB ~] 
[root@GGB ~] 
[root@GGB ~] systemctl  start   mysql.service 
[root@GGB ~] systemctl  status  mysql.service 
● mysql.service - MySQL Server
   Loaded: loaded (/etc/systemd/system/mysql.service; enabled; vendor preset: disabled)
   Active: active (running) since 五 2024-07-12 01:21:31 CST; 2s ago
  Process: 3738 ExecStop=/usr/local/mysql/bin/mysqladmin shutdown (code=exited, status=1/FAILURE)
 Main PID: 5097 (mysqld)
   CGroup: /system.slice/mysql.service
           └─5097 /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/3306/data
[root@GGB ~] 

步骤五:验证数据库密码

[root@GGB ~] mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.26 MySQL Community Server - GPL

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

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> 

相关推荐

  1. 数据库mysql忘记密码解决办法

    2024-07-11 22:30:03       22 阅读
  2. mysql数据库安装_修改密码_忘记密码(修改)

    2024-07-11 22:30:03       33 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-11 22:30:03       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-11 22:30:03       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-11 22:30:03       58 阅读
  4. Python语言-面向对象

    2024-07-11 22:30:03       69 阅读

热门阅读

  1. GET正常,POST获取不到数据

    2024-07-11 22:30:03       20 阅读
  2. scoop安装在D盘

    2024-07-11 22:30:03       22 阅读
  3. 华为机考真题 -- 密码解密

    2024-07-11 22:30:03       19 阅读
  4. 设计模式——单例模式

    2024-07-11 22:30:03       21 阅读
  5. C# 反射

    2024-07-11 22:30:03       20 阅读
  6. Ubuntu 软件源404not found原因及解决办法

    2024-07-11 22:30:03       17 阅读
  7. 拓扑排序(算法篇)

    2024-07-11 22:30:03       23 阅读
  8. SQL 存储过程

    2024-07-11 22:30:03       24 阅读
  9. 大数据面试题之数据湖

    2024-07-11 22:30:03       21 阅读
  10. MySQL常用命令

    2024-07-11 22:30:03       17 阅读
  11. 多态

    多态

    2024-07-11 22:30:03      22 阅读
  12. 面向本科生的智能品牌传播策略优化

    2024-07-11 22:30:03       27 阅读
  13. 数字化转型

    2024-07-11 22:30:03       15 阅读