码迷,mamicode.com
首页 > 数据库 > 详细

MySQL数据库管理员密码忘记如何修改?

时间:2020-12-19 11:54:34      阅读:1      评论:0      收藏:0      [点我收藏+]

标签:lin   stat   local   run   mysql数据库   monitor   lte   err   exec   

系统环境: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> 

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

  

 

MySQL数据库管理员密码忘记如何修改?

标签:lin   stat   local   run   mysql数据库   monitor   lte   err   exec   

原文地址:https://www.cnblogs.com/molson/p/14132583.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!