Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ALTER USER root@localhost IDENTIFIED VIA mysql_native_password; -- fails with syntax error

Tags:

mysql

mariadb

Trying to enable regular password-based auth according to the below page: https://mariadb.com/kb/en/library/authentication-plugin-unix-socket/

The page suggests the following code:

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

but on my machine it fails with a syntax error:

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)
like image 386
Blaine Lafreniere Avatar asked May 09 '19 04:05

Blaine Lafreniere


2 Answers

If you're running MariaDB < 10.2, the ALTER USER command will not work, as stated above.

To change the authentication method, use:

UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE user = 'root';
like image 172
mwieczorek Avatar answered Sep 19 '22 22:09

mwieczorek


ALTER USER "MariaDB starting with 10.2.0"

So 10.1 is too early. Also mysqld --version or SELECT VERSION() to show the version. mysql --version only shows the client version.

like image 43
danblack Avatar answered Sep 18 '22 22:09

danblack