MySQL数据库管理员密码忘记如何修改?
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      0128                              *:22                                          *:*
5 LISTEN      0128                          [::]: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/'.
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)
  出现如上信息,说明数据库密码修改成功。
五:停⽌数据库的进程并登录验证数据库
2020新春祝福贺词
停⽌数据库的相关进程
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>
  由以上信息可知,数据库登录成功 

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。