前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >排障集锦:九九八十一难之第七难!mysql数据库登录密码忘记了

排障集锦:九九八十一难之第七难!mysql数据库登录密码忘记了

作者头像
不吃小白菜
发布2020-09-03 10:22:26
8070
发布2020-09-03 10:22:26
举报

Mysql5.7之后版本破解

vim /etc/my.cnf 进入到配置文件 skip-grant-tables 加上此字段 跳过密码直接登录 登录后对mysql库中的user表中authentication_string 密码字段进行更改

代码语言:javascript
复制
[root@localhost ~]# vim /etc/my.cnf    '进入到配置文件'
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock
server-id = 1
skip-grant-tables            '添加此行'
[root@localhost ~]# systemctl restart mysqld 


[root@localhost ~]# mysql    '再次登录发现不需要密码了'
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.17 Source distribution

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> 
代码语言:javascript
复制
mysql> desc mysql.user;  '查看密码字段'

authentication_string    '此字段就是密码字段  当然这一步是在你记不住密码字段的情况下'
mysql> select user,host,authentication_string from mysql.user;   '查看登录名  登录终端  密码'
+-----------+-----------+-------------------------------------------+
| user      | host      | authentication_string                     |
+-----------+-----------+-------------------------------------------+
| root      | localhost | *7A8BBCB18A250055A6BB98ECFA33A8174D219504 |
| mysql.sys | localhost | *THISISNOTAVALIDPASSWORDTHATCANBEUSEDHERE |
| root      | %         | *6691484EA6B50DDDE1926A220DA01FA9E575C18A |
+-----------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)
mysql> update mysql.user set authentication_string=password('Abc123') where user='root'     'updata  跟新表内容  user表 当user为root的情况下  将其密码设置为Abc123'
    -> ;
Query OK, 1 row affected, 1 warning (0.01 sec)
Rows matched: 2  Changed: 1  Warnings: 1

[root@localhost ~]# vim /etc/my.cnf
#skip-grant-tables   '将刚才的字段进行注释'
[root@localhost ~]# systemctl restart mysqld    '每次更改完文件都要进行重启服务'


[root@localhost ~]# mysql     '再次登录发现需要验证密码了'  
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
[root@localhost ~]# mysql -u root -p"Abc123"   '用刚刚设置的密码再次尝试登录'
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.17 Source distribution

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> 

Mysql5.7之前版本破解

vim /etc/my.cnf 进入到配置文件 skip-grant-tables 加上此字段 跳过授权表 登录后对mysql库中的user表中password 密码字段进行更改 只有密码字段不一样

代码语言:javascript
复制
[ root@mysql1 ~ ]# vim /etc/my.cnf
[mysqld]
skip-grant-tables
[root@mysql1 ~]# service mysqld restart
[root@mysql1 ~ ]# mysql
mysql> update mysql.user set passvord=password("456") where user="root" and host="localhost";
mysql> flush privileges;  '刷新一下表'
mysql> \q
[root@mysql1 ~]# vim /etc/my.cnf
[mysqld]
# skip-grant-table
[root@mysql1 ~]# service mysqld restart
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-08-18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Mysql5.7之后版本破解
  • Mysql5.7之前版本破解
相关产品与服务
云数据库 SQL Server
腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档