进数据库后,use mysql //选择mysql这个库,因为mysql的root密码存放在这个数据库里。
show tables //查看下mysql库里有哪些表,我们需要操作的用户名密码都在user表里。
desc user //查看下user表有哪些字段。
update user set password=password(‘123456‘) where user="root"; //用户选root,可以随便更改成任意密码,我这里设置的123456,password()是mysql密码加密的一个函数。有些数据要执行update user set authentication_string=password(‘coship‘) where user="root";才行
发现行不通,
改用ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘123456‘;
报错:The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement
flush privileges;
再次:ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘123456‘;
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
执行:SHOW VARIABLES LIKE ‘validate_password%‘;
set global validate_password.policy=0;set global validate_password.length=6;
然后再次执行:ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘123456‘;