环境mysql5.7版本 口令字段是authentication_string
首先停止mysql服务,修改配置文件
systemctl stop mysqld
打开/etc/my.cnf配置文件,在[mysqld]下添加 skip_grant_tables
systemctl start mysqld
在命令行内直接输入mysql即可不需要认证即可登录
进入 mysql> 环境后,重设root口令为123456:
update mysql.user set authentication_string=password('123456') where user='root' and host='localhost';
flush privileges;
修改口令后,删除[mysqld]下添加 skip_grant_tables
重启mysql服务,尝试用新口令登录;
systemctl restart mysqld
mysql -uroot -p123456
然后在查询或执行一些语句会报错;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this
若报错执行下面语句,修改口令长度位1,默认为8,
mysql> set global validate_password_policy=0;
mysql> set global validate_password_length=1;
mysql> alter user 'root'@'localhost' identified by '123456';
然后就不会报错了
参考:
https://www.cnblogs.com/zgqbky/p/11720406.html
https://blog.csdn.net/qq_44792624/article/details/107426590