专栏首页用户7721898的专栏排障集锦:九九八十一难之第七难!mysql数据库登录密码忘记了

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

Mysql5.7之后版本破解

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

[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> 
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 密码字段进行更改 只有密码字段不一样

[ 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

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • 人生苦短,我用k8s--------------Pod资源控制进阶管理

    尽管只能在单个容器上指定请求和限制,但是谈论Pod资源请求和限制很方便。特定资源类型的 Pod资源请求/限制是Pod中每个Container的该类

    不吃小白菜
  • 排障集锦:九九八十一难之第六难!(98)Address already in use: AH00072: make_sock: could not bind to address ::80

    不吃小白菜
  • 排障集锦:九九八十一难之第一难!linux发现交换文件无法打开文件!

    E325: 注意 发现交换文件 “/etc/.named.rfc1912.zones.swp” 所有者: root 日期: Mon Jul 6 23...

    不吃小白菜
  • ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES/NO) 解决方案1.停止mysql

    初次安装mysql,net start mysql,然后输入mysql -u root -p,

    一个会写诗的程序员
  • MYSQL设置远程账户登陆总结

    打开 /etc/mysql/my.cnf 文件,找到 bind-address = 127.0.0.1 修改为 bind-address = 0.0.0.0

    流柯
  • Access denied for user ''@'localhost' to

    提示:ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'mysql'...

    双面人
  • MySQL 主从同步架构中你不知道的“坑”

    结论:此种模式下此配置对默认的库进行不同步数据库,需要增加相关表的参数,最后测试得出不加replicate-ignore-db = mysql参数,同样对默认的...

    民工哥
  • [MySQL] 解决Error 1698: Access denied for user 'root'@'localhost'

    当程序中使用root账号连接mysql时报以下错误,但是使用命令行是可以正常连接的,那么就查询下mysql数据库的user表,查看下当前用户的密码加密方式,看看...

    陶士涵
  • 服务器的Mysql初始化设置

    继上篇博客记录了服务器的初始化安全设置之后,本篇文章会记录Mysql数据库的初始化安全设置。在操作mysql之前,最好先行备份,毕竟有“备”无患嘛。

    Originalee
  • mysql 3.x拿webshell

    mysql> Create TABLE demo (sanr text NOT NULL);

    py3study

扫码关注云+社区

领取腾讯云代金券