可以通过绕过权限检查的方式临时获取数据库访问权限
方法1
停止服务
systemctl stop mysql
修改配置
vim /etc/mysql/mysql.conf.d/mysqld.conf
[mysqld]
skip-grant-tables
启动服务
systemctl start mysql
修改密码
flush privileges;
alter 'root'@'localhost' identified by 'password';
exit;
注释配置
vim /etc/mysql/mysql.conf.d/mysqld.conf
[mysqld]
#skip-grant-tables
重启服务
systemctl restart mysql
方法2
停止mysql服务
systemctl stop mysql
绕过权限检查启动mysql
mysqld_safe --skip-grant-tables --socket=/tmp/mysql.sock &
进入mysql
mysql -S /tmp/mysql.sock
更改密码
flush privileges;
alter 'root'@'localhost' identified by 'password';
exit;
结束服务
pkill mysqld
启动服务
systemctl start mysql