前言
忘记MySQL服务密码在公司中是大忌的!
有的时候,时候长了可能会忘记密码,为了不被上司喷到狗血淋头,你需要看看这篇博文!
密码破解
1. 停止MySQL服务
[root@mysql ~]# service mysql stop
Redirecting to /bin/systemctl stop mysql.service
2. 修改配置文件/etc/my.cnf
[mysqld_safe]
[client]
socket=/data/mysql/mysql.sock
[mysqld]
socket=/data/mysql/mysql.sock
port = 3306
open_files_limit = 8192
innodb_buffer_pool_size = 512M
character-set-server=utf8
skip-grant-tables #跳过密码认证过程
[mysql]
auto-rehash
prompt=\u@\d \R:\m mysql>
添加字段----skip-grant-tables #跳过密码认证过程
3.启动MySQL进程
[root@mysql1 mysql]# service mysqld start
Starting MySQL. SUCCESS!
4.登录MySQL,不需要密码
[root@mysql1 mysql]# mysql -uroot
5.更改密码
root@(none) 23:20 mysql>alter user 'root'@'localhost' identified by 'Sanchuang1234#';
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
跳过密码登录,无法执行语句
原因:没有加载权限表。
6.刷新权限表
root@(none) 23:22 mysql>flush privileges;
Query OK, 0 rows affected (0.05 sec)
root@(none) 23:26 mysql>alter user 'root'@'localhost' identified by 'Sanchuang1234#';
Query OK, 0 rows affected (0.00 sec)
root@(none) 23:27 mysql>exit
flush privileges 刷新权限,会加载原来没有加载的权限表
修改密码成功
7.修改配置文件,正常密码认证,不需跳过权限表
[mysqld_safe]
[client]
socket=/data/mysql/mysql.sock
[mysqld]
socket=/data/mysql/mysql.sock
port = 3306
open_files_limit = 8192
innodb_buffer_pool_size = 512M
character-set-server=utf8
#skip-grant-tables #跳过密码认证过程
[mysql]
auto-rehash
prompt=\u@\d \R:\m mysql>
注释掉 skip-grant-tables 字段
8.重新登陆
[root@mysql1 mysql]# mysql -uroot -p'Sanchuang1234#'
密码破解成功!
MySQL密码破解就介绍到这里啦!