您的位置:首页 > 运维架构 > Shell

xshell中数据库忘记密码后重新设置密码的解决办法!

2020-07-22 22:42 411 查看

数据库忘记密码后重新设置:

1.修改主配置文件,添加 skip-grant-tables,跳过授权表

vim /etc/my.cnf
[root@zhai ~]# vim /etc/my.cnf

[mysqld]
skip-grant-tables
如下图

2.重启mysqld

systemctl restart mysqld
[root@zhai ~]# systemctl restart mysqld

3.无需输入密码进入mysql,执行修改密码的命令,刷新并退出

mysql -u root -p

直接回车进入数据库,无需输入密码
mysql> use mysql;
mysql> update user set authentication_string=password(“123456”) where User=“root”;
mysql> flush privileges;
mysql> quit;

[root@zhai ~]# mysql -u root -pEnter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> update user set authentication_string=password("123456") where User="root";
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

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

mysql> quit;
Bye

4.恢复主配置文件,即进入 vim /etc/my.cnf,然后把skip-grant-tables注释掉,最后重启mysqld

systemctl restart mysqld![在这里插入图片描述](https://img-blog.csdnimg.cn/20200722223022258.PNG)
[root@zhai ~]# systemctl restart mysqld[root@zhai ~]# vim /etc/my.cnf[root@zhai ~]# mysql -u root -pEnter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: