亲测环境:centos7+mysql5.7
跳过密码验证
vi /etc/my.cnf
[mysqld]
skip-grant-tables
重启mysqld
systemctl restart mysqld
无密码进入mysql命令框
mysql -uroot
进入mysql数据库
use mysql;
修改root密码为root(*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B)为设置密码root
delete from user where user = ‘root’;
INSERT INTO user
VALUES (‘localhost’, ‘root’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘Y’, ‘’, ‘’, ‘’, ‘’, 0, 0, 0, 0, ‘mysql_native_password’, ‘*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B’, ‘N’, ‘2018-12-10 13:21:57’, NULL, ‘N’);
update user set host = ‘%’ where user = ‘root’;
update user set account_locked=“N” where user=“root” or Host=“localhost” or host=“127.0.0.1”;
关闭跳过密码验证
vi /etc/my.cnf
[mysqld]
#skip-grant-tables
重启mysqld
systemctl restart mysqld
mysql -u root -p
root