美文网首页
MySQL 密码找回

MySQL 密码找回

作者: 我只是一个小白 | 来源:发表于2018-12-13 20:54 被阅读0次

环境

centos 7.x
MySQL 5.7.20

前提

  • 1.MySQL 可以重启
  • 2.可以登录服务器

操作

  • 1.原密码
[root@1]# mysql -uroot -p12345
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 4
Server version: 5.7.20-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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.

(root@localhost) [(none)]>

  • 2.假设密码忘记
- 1.配置 my.cnf
vim /etc/my.cnf // 注意每个配置文件不一定位置相同
[mysqld]
skip-grant-tables // 写入 my.cnf 配置文件

- 2.重启 MySQL
service mysqld restart // 重启数据库方法根据实际情况决定
Shutting down MySQL.. SUCCESS!
Starting MySQL... SUCCESS!
  • 3.修改密码
[root@1]# mysql // 以上做完之后,可以直接登录
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.20-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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.

(root@localhost) [(none)]> alter user 'root'@'localhost' identified by '123'; // 这时由于系统检测 skip grant,是不会让你修改密码的。
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

(root@localhost) [(none)]>flush PRIVILEGES; // 再次让密码生效
Query OK, 0 rows affected (0.01 sec)

(root@localhost) [(none)]>alter user 'root'@'localhost' identified by '123'; // 修改密码
Query OK, 0 rows affected (0.00 sec)

(root@localhost) [(none)]>flush tables; // 刷内存数据
Query OK, 0 rows affected (0.00 sec)

(root@localhost) [(none)]>quit // 退出
Bye
  • 4.成功现象
[root@1]# mysql // 密码生效,skip grant 失效
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

[root@1]# mysql -uroot -p123 // 这时使用密码登录,就可以正常使用了
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 4
Server version: 5.7.20-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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.

(root@localhost) [(none)]>

注意:记得把配置文件中 skip grant 注释掉

相关文章

  • mysql忘记root用户密码了?来看看怎么找回吧

    mysql忘记root用户密码找回步骤 修改或找回root密码步骤1.修改MySQL的登录设置: 在[mysqld...

  • mysql密码找回

    以下操作均在管理员情况下1.关掉mysql服务net stop mysql下图是开启了服务和没开启服务两种情况下关...

  • MySQL 密码找回

    环境 centos 7.xMySQL 5.7.20 前提 1.MySQL 可以重启 2.可以登录服务器 操作 1....

  • Mysql 忘记密码找回

    停止Mysql服务 使用mysql_safe 附带的 “--skip-grant-tables”(忽略授权登录验证...

  • Mysql忘记root密码找回 详细教程

    公司的测试数据库要新增一个普通用户,但要root 账号权限root密码忘记了, 需要重置, 网上搜不太详细,整理了...

  • 网站帮助使用说明

    帮助目录 - 会员管理 + 会员注册 + 会员登录 + 密码找回

  • Mysql数据库登录及密码找回

    1.tcp/ip方式登录 2.socket登录 3.找回数据库密码 3.1实际操作如下:

  • iOS用分段控制器UISegmentedControl来写注册/

      我们在写注册界面时,写注册和密码找回按钮时,且注册和密码找回按钮在一起时,如下图所示:   我们常常需要两个按...

  • 密码找回

    这是2022年的最后一个月了!打开某个小程序,不经意看到,今天距离2023年中招考试还有202天! 瞧吧,时间总是...

  • Web实战之密码找回

    密码找回是几乎所有Web应用都需要的,一般均通过邮件的方式,这里我先实现一种最简单的密码找回——将密码重置为随机字...

网友评论

      本文标题:MySQL 密码找回

      本文链接:https://www.haomeiwen.com/subject/owfihqtx.html