[已解决]mysql设置root初始密码报错:the right syntax to use near ‘identified by ‘123456” at line 1

Mysql初始安装后,默认有一个无密码的root超级管理员账户,自然需要先设置密码。

> alter user 'root'@'localhost' identified by '123456';

然而,出现报错:

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 ‘identified by ‘123456” at line 1

不知道什么原因,看见网上很多写法都如此,就是行不通,可能是与mysql版本有关。

最后换了一种写法,顺利通过:

> SET PASSWORD  FOR root@localhost = password('123456');
> flush privileges;

参考资料:https://blog.csdn.net/qq_44985699/article/details/131303489