systemctl stop mysql
2,修改配置跳过密码检测
修改my.cnf
在mysqld后便追加或者注释
skip_grant_tables
skip_networking
启动服务:systemctl start mysqld
或者直接启动:mysqld_safe --skip_grant_tables --skip_networking
3,mysql进入
修改密码:
update mysql.user set authentication=password('loge0001') where user='root'; -- SET PASSWORD FOR root@localhost=PASSWORD('123456');
-- update mysql.user set authentication_string=PASSWORD('china') where user='root' and host='localhost';
或者alter user 'root'@'localhost' identified by ‘123456’; 最后一种通用
如果执行时候出现:
ERROR 1290 (HY000): The MySQL server is running with the --skip-grant-tables 则执行如下语句:
flush privileges;说明;在之前修改密码是用:update mysql.user set password=password('loge0001') where user='root';
4,取消第二部中的修改,重新启动服务,systemctl restart mysql