I've installed mariadb from Ubuntu 15.04 repositories using the Ubuntu software center or at the command prompt (apt-get install maraidb-server), but no password is asked for root user. Now I'm able to connect to mysql on command line without password, but connecting using Mysql-Workbench or python mysqldb library failed with the "Access denied for user 'root'@'localhost'" message
MariaDB installed without password prompt
38.5k views Asked by mtoloo AtThere are 6 answers
For a MariaDB version greater than or equals to 10.2.0, the response of user3054067 is correct.
For a MariaDB version less than 10.2.0, you can do this :
me$ sudo su -
root$ mysql -u root
MariaDB [(none)]> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('new_password');
Query OK, 0 rows affected, 1 warning (0.00 sec)
MariaDB [(none)]> UPDATE mysql.user SET plugin='mysql_native_password' WHERE User='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
In another terminal,
me$ mysql -u root -pnew_password
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 83
Server version: 10.0.38-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
If you want to switch to the mysql_native_password authentication plugin, then you could use
ALTER USER root@localhost IDENTIFIED VIA mysql_native_password;
SET PASSWORD = PASSWORD('new_password');
For further information see https://mariadb.com/kb/en/authentication-plugin-unix-socket/
it is common for root to have password-less access if accessing from localhost, I recommend this setting to be left alone.
I also recommend that you create a user with less permissions and allow that user to login remotely.
create user my_admin identified by '12345';
create database my_database;
grant all on my_database.* to my_admin;
This way you have a little more security.
If you do need to connect as root from a tool like workbench, you can configure those tools to create an ssh tunnel and connect to the database as localhost.
As @Pedru noticed, the "Access denied for user 'root'@'localhost'" message is due to the fact that Debian and Ubuntu enable the UNIX_SOCKET Authentication Plugin plugin by default, allowing passwordless login (See also Authentication Plugin - Unix Socket). This is not an installation problem.
It means that if you type mysql -u root -p
in the Linux Shell, root
is actually the Linux root (or linked to it, I don't know how this actually works). So that if you logged on Linux with another account, you will get an error:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
. Better type sudo mysql -u root -p
or sudo mysql -u root
if the password is not yet defined.
Starting with MariaDB 10.4
root@localhost
account is created with the ability to use two authentication plugins:That is why you don't need a password to login on a fresh install.
But then another quote:
So setting
plugin = ''
will force it to use password based authentication. Make sure you set a password before that.