技术知识库

帮助中心 >  产品文档 >  数据库 >  MySQL修改密码报错:ERROR 1064 (42000) You have an error in your SQL syntax;

MySQL修改密码报错:ERROR 1064 (42000) You have an error in your SQL syntax;

蓝队云小课堂:

在用 命令行 运行的 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 'xxx' at line 1


这其实是 MySQL 的 版本不同 所导致的支持的修改密码的 语法不同 所造成的问题,接下来就来看看不同版本的MySQL所支持的语法。(以下均为将密码改为“123465”的示例)


5.6 版本:

① update mysql.user set password=password('123456') where User="root" 

    and Host = "localhost";

② set password for root@localhost = password('123456');

5.7 以上版本,password 字段被设置为了authentication_string,因此更新命令为:

update mysql.user set authentication_string=password('123456') 

    where User="root" and Host="localhost";

8.0 以上的版本,以上的命令都不支持,有以下两个命令可用:

① alter user 'root'@'localhost' identified by 'root';

② set password for root@localhost = '123456';

更多小知识,可联系蓝队云一起探讨。


提交成功!非常感谢您的反馈,我们会继续努力做到更好!

这条文档是否有帮助解决问题?

非常抱歉未能帮助到您。为了给您提供更好的服务,我们很需要您进一步的反馈信息:

在文档使用中是否遇到以下问题: