相信大家都遇到过这种情况,在用 命令行 运行的 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 'xxxxxxxxxxxxxxxxxxxxxxxxx' at line 1

接下来的内容划重点,请认真看 !!!!!!!!!!!!!!

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

  1. 5.6 版本
	① update mysql.user set password=password('123456') where User="root" 
 	  and Host = "localhost";
	② set password for root@localhost = password('123456');
  1. 5.7 以上版本,password 字段被设置为了authentication_string,因此更新命令为:
	update mysql.user set authentication_string=password('123456') 
    where User="root" and Host="localhost";
  1. 8.0 以上的版本,以上的命令都不支持,有以下两个命令可用(MySQL的安装与配置——详细教程(转载)里面修改密码用的就是这个最新的命令):
	① alter user 'root'@'localhost' identified by 'root';
	② set password for root@localhost = '123456';

补充:来自评论~

更多推荐

MySQL修改密码时,报错ERROR 1064 (42000)【新版MySQL修改密码命令有所变更】