暂无图片
暂无图片
1
暂无图片
暂无图片
暂无图片

MySQL忘记密码,更改root密码操作

原创 ShyNodes 2022-04-02
378

MySQL忘记密码,更改root密码操作

在配置文件中添加如下参数,路过权限限制

skip_grant_tables

重启数据库

/etc/init.d/mysqld restart


在重启后登录数据库,将mysql.user表中root密码字段设置为空

登录:
[root@test236 ~]# mysql -uroot -p
Enter password:     ###### 此处直接回车
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31-log 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.user表
mysql> update mysql.user set authentication_string='' where user ='root';
Query OK, 1 row affected (5.01 sec)

将配置文件中的skip_grant_tables参数注释掉,再重启数据库,修改密码

[root@test236 ~]# vi /etc/my.cnf
[root@test236 ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!
[root@test236 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.31-log

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> alter user root@localhost identified by '123';
Query OK, 0 rows affected (5.01 sec)

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





最后修改时间:2022-04-02 22:39:34
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论