I guess I haven’t installed MariaDB for a while cause last time the installation was a snap. A few minutes and you were up and running. Today a roadblock appeared to extend the installation time considerably.
Access denied for user 'root'@'localhost' (using password: YES)
I don’t know how long MySQL Authentication Plugins have been around, but they’re in full force now. Actually, its very cool tech. The downside is that most of us want to just load our database server like we have for years and get back to writing code.
Simply setting your root password in the new $ sudo mysql_secure_installation won’t be enough to login as root, which is pretty damned frustrating to be honest.
Onto the Analysis
To get a bit more information you can view the status of the MariaDB Server.
$ sudo service mysql status
Where you may see (in bright red font) something like:
Dec 05 09:57:57 montana mysqld[7774]: 161205 9:57:57 [Warning] 'user' entry 'root@localhost' has both a password and an authentication plugin specified. The password will be ignored.
The password will be ignored. That’s just swell!
To the Fix
We need to stop our MariaDB server with $ sudo service mysql stop and fire up the daemon without any grant inspections.
$ sudo mysqld_safe --skip-grant-tables
We can’t simply set a password as we are used to doing, we need to specify the Authentication Plugin.
UPDATE mysql.user SET authentication_string = PASSWORD('mypassword'), plugin = 'mysql_native_password' WHERE User = 'root' AND Host = 'localhost';
Notice plugin = ‘mysql_native_password’.
Be sure to mysql> FLUSH PRIVILEGES; and restart the MariaDB Server in normal mode and you should be good to login. You may have to kill the mysqld PID ($ sudo kill -9 [PID]) before restarting the DB Server with
$ sudo service mysql start