1、修改配置文件my.cnf
vim /etc/my.cnf
skip-grant-tables //在[mysqld]下面添加参数,设置无密码登录
2、重启mysql,并登录
systemctl restart mysqld
3、清空密码,将配置skip-grant-tables 注释,并重启mysql,再次登录测试
use mysql
update user set authentication_string='' where user = 'root'; //清空密码
systemctl restart mysqld
4、由于mysql对密码进行了限制,如果密码设置弱密码,需要修改设置
4.1、查看密码规则
show variables like 'validate_password%';
4、设置密码长度为6,密码验证强度为0/low
set global validate_password_length=6;
set global validate_password_policy=0;
5、设置密码为123456,并登录测试
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';