命令:vim /etc/my.conf;在MysqLd下增加一行
原内容:
datadir=/var/lib/MysqL socket=/var/lib/MysqL/MysqL.sock
修改后的:
datadir=/var/lib/MysqL socket=/var/lib/MysqL/MysqL.sock skip-grant-tables (新增的)
2.重启MysqL;
命令:
service MysqLd restart
3.进入MysqL;
命令:
MysqL; use MysqL; update user set authentication_string=password('a') where user='root'; flush privileges ; exit
执行的结果是这样的:
4.去掉1中增加的那一行命令;
5.重启MysqL,命令同2;
6.进入MysqL,
命令:
MysqL -uroot -p
回车输入密码,即可见如下图:
登录后报错:
You must reset your password using ALTER USER statement before executing
解决办法:
1.设置密码
SET PASSWORD = PASSWORD(‘your new password‘);
这里密码必须复杂,否则会报错
Your password does not satisfy the current policy requirements
2.设置密码永久不会改变
alter user 'root'@localhost password expire never;
3.刷新数据库
flush privileges;
大功告成!
原文链接:https://www.f2er.com/centos/379697.html