通过mysql_native_password来标识ALTER USER root @ localhost; -因语法错误而失败

时间:2019-05-09 04:23:41

标签: mysql mariadb

尝试根据以下页面启用常规的基于密码的身份验证: https://mariadb.com/kb/en/library/authentication-plugin-unix-socket/

该页面建议以下代码:

ALTER USER root@localhost IDENTIFIED VIA mysql_native_password;
SET PASSWORD = PASSWORD('foo');

但是在我的机器上,它失败并出现语法错误:

MariaDB [(none)]> ALTER USER root@localhost IDENTIFIED VIA mysql_native_password;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'USER root@localhost IDENTIFIED VIA mysql_native_password' at line 1
MariaDB [(none)]> SET PASSWORD = PASSWORD('foo');
Query OK, 0 rows affected, 1 warning (0.00 sec)

2 个答案:

答案 0 :(得分:2)

如果您正在运行MariaDB <10.2,则如上所述,ALTER USER命令将不起作用。

要更改身份验证方法,请使用:

UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root';

答案 1 :(得分:0)

ALTER USER“从10.2.0开始的MariaDB”

所以10.1还为时过早。还要mysqld --versionSELECT VERSION()来显示版本。 mysql --version仅显示客户端版本。