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