14

I am trying to setup MariaDB (10.0.29) on Ubuntu (16.04.02). After I installed it and started the process (sudo service mysql start), I cannot login as root even though I originally set the password to blank.

Ie mysql -u root will deny me access. I logged in through sudo mysql and checked the user table, ie. select user, password, authentication_string from mysql.user and as expected:

+---------+----------+-----------------------+ 
| User    | password | authentication_string |
+---------+----------+-----------------------+
| root    |          |                       |
+---------+----------+-----------------------+

I also created a new user, ie. create user 'test'@'localhost' identified by ''; and when I try to do mysql -u test (empty password), it works as expected and logs me in.

The user table looks like this:

+---------+----------+-----------------------+
| User    | password | authentication_string |
+---------+----------+-----------------------+
| root    |          |                       |
| test    |          |                       |
+---------+----------+-----------------------+

So, can anyone tell me why I cannot login as root with empty password but I can login as test?

4
  • 1
    Empty password and no password might be treated differently.
    – tadman
    Apr 12, 2017 at 21:34
  • I had similar experience. First, on install I had not asked to set root password. I tried to reset root password, but still did not got access. And reinstalled and got into same situation. Also Ubuntu 16.04 64bit. Installed mysql afterwards
    – w.k
    Apr 12, 2017 at 22:00
  • 1
    You can reset your root password as mentioned in this link
    – daBigBug
    Apr 12, 2017 at 22:12
  • You can login using mysql -uroot -p, when the terminal ask for the password, just press the enter key.
    – Hackerman
    Apr 13, 2017 at 15:43

3 Answers 3

33

Unlike native MariaDB packages (those provided by MariaDB itself), packages generated by Ubuntu by default have unix_socket authentication for the local root. To check, run

SELECT user, host, plugin FROM mysql.user;

If you see unix_socket in the plugin column, that's the reason.

To return to the usual password authentication, run

UPDATE mysql.user SET plugin = '' WHERE plugin = 'unix_socket';
FLUSH PRIVILEGES;

(choose the WHERE clause which fits your purposes, the one above is just an example)

1
  • This helped. I understand instead of using 'root' and password, ubuntu forced mariadb to use its own authentication when logged in as root.
    – Rahul
    Sep 10, 2018 at 6:59
6

The issue you're having is due to changes in the authentication system of MariaDB 10.4:

As a result of the above changes, the open-for-everyone all-powerful root account is finally gone. (...) because the root account is securely created automatically. They are created as: CREATE USER root@localhost IDENTIFIED VIA unix_socket OR mysql_native_password USING 'invalid'

If you really want to access your DB as root, you should login via cli mariadb -p and run:

ALTER USER root@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD("your-password-here");

Source: https://mariadb.com/kb/en/library/authentication-from-mariadb-104/#altering-the-user-account-to-revert-to-the-previous-authentication-method

About the other solution bellow: they won't work because MariaDB won't also allow you to update the plugin column: ERROR 1348 (HY000): Column 'plugin' is not updatable.~


Update 2020: although my solution above works it replaces the default root unix_socket authentication with a password. I've noticed this breaks tasks such as mariadb upgrade / your own maintenance scripts that would expect to be able to connect to the DB without extra passwords when running as root.

My suggestion is to add a new root login as follows:

CREATE USER `root`@`%` IDENTIFIED WITH mysql_native_password using PASSWORD('your-password-here');
GRANT ALL PRIVILEGES ON *.* TO `root`@`%` WITH GRANT OPTION;
FLUSH PRIVILEGES;

This will effectively still allow for the default behavior of root login and add external access to the DB using the password.

1
  • 1
    This also enables MariaDB Mac OS root login
    – Larry K
    Dec 23, 2019 at 21:14
2

I struggled with this for some time. My Ubuntu comes with MariaDB (10.0.31) by default. After reinstalling a few times and changing the plugins to various suggestions - I still could not login properly to mysql.

In the end I installed the latest MariaDB (10.2.12) from the repo : https://downloads.mariadb.org/mariadb/repositories/

I was able to login properly immediately.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.