重置Mysql root 密码
一、原因:原来安装mysql的时候,root的密码中含有一个字符"!",结果在实际使用中连接mysql的时候却总是提示"!"不合法,所以只能修改密码了
二、重置命令
1. 使用下面的命令
update user set password = password('new-password') where user = 'root' ;
错误提示是没有password字段,看回表才发现是没有password,这个是MySQL8.0版本一下才有的。
2. 然后看到user表中有个authentication_string,接着使用下面的命令:
update user set authentication_string= password('new-password') where user = 'root' ;
这个命令是可以的,完整的命令:
use mysql;
update user set authentication_string=PASSWORD('new-password') where user='root';
FLUSH PRIVILEGES
使用上面的命令后重新查看authentication_string有没有改变,要是改变了就说明成功了。
MySQL 8.0以上使用这个方法也有可能是不成功的,因为有的文章说MySQL 8.0 中没有PASSWORD('new-password')
这个方法了。
3. 要是还是没有更改,可以使用下面的命令:
use mysql;
ALTER user 'root'@'localhost' IDENTIFIED BY 'new-password';
FLUSH PRIVILEGES;