修改mysql的密码时遇到问题ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corre

由于找不到mysql的初始密码,我用免密码的方式在cmd中进入mysql对密码做了修改,并且最后成功修改了,但是走了一些弯路,就此记录一下。
注意 :我想要改为的密码为 mysql,大家想要什么密码设自己喜欢的就行

进入mysql后修改密码失败情况:
1.输入:update user set password=password('mysql') where user='root' and host='localhost';
注:password=password(‘mysql’),单引号里的就是密码:mysql
报错:ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘(“123456”) where user=“root”’ at line 1
网上有方法说修改一下user和host大小写能够成功

update user set password=password('mysql') where User='root' and Host='localhost';

但是我依旧没用成功

2.输入:ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql';
注:IDENTIFIED BY ‘mysql’,单引号里的就是密码:mysql
报错:ERROR 1290(HY000)
看来我直接免密码进来的,用这句操作也行不通。

3.先输入:flush privileges;
再输入:set password for root@localhost=password('mysql');
报错:又出现ERROR 1064 (42000)

修改成功的情况:
4.先输入:flush privileges;
再输入:ALTER USER 'root'@'localhost' IDENTIFIED BY 'mysql';
终于成功啦!
具体如下图:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/lic1697067085/article/details/120234287