MariaDB installed without password prompt
Solution 1
Starting with MariaDB 10.4 root@localhost
account is created with the ability to use two authentication plugins:
- First, it is configured to try to use the
unix_socket
authentication plugin. This allows theroot@localhost
user to login without a password via the local Unix socket file defined by the socket system variable, as long as the login is attempted from a process owned by the operating systemroot
user account.- Second, if authentication fails with the
unix_socket
authentication plugin, then it is configured to try to use themysql_native_password
authentication plugin. However, an invalid password is initially set, so in order to authenticate this way, a password must be set withSET PASSWORD
.
That is why you don't need a password to login on a fresh install.
But then another quote:
When the plugin column is empty, MariaDB defaults to authenticating accounts with either the
mysql_native_password
or themysql_old_password
plugins. It decides which based on the hash used in the value for the Password column. When there's no password set or when the 4.1 password hash is used, (which is 41 characters long), MariaDB uses themysql_native_password
plugin. Themysql_old_password
plugin is used with pre-4.1 password hashes, (which are 16 characters long).
So setting plugin = ''
will force it to use password based authentication. Make sure you set a password before that.
sudo mysql -u root
[mysql] use mysql;
[mysql] update user set plugin='' where User='root';
[mysql] flush privileges;
[mysql] \q
Solution 2
sudo mysql -u root
[mysql] use mysql;
[mysql] update user set plugin='' where User='root';
[mysql] flush privileges;
[mysql] \q
This needs to be followed by following command
# mysql_secure_installation
Solution 3
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.
Solution 4
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.
Solution 5
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/
Related videos on Youtube
mtoloo
Updated on November 26, 2020Comments
-
mtoloo over 3 years
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
-
arkascha almost 9 yearsThis is not a question of the installation. Those servers always create the root account without password. You have to internally change it as documented. About the workbench or similar failing: whyever that is, but the problem will be solved the moment you have set a password for the account which you have to do anyway.
-
mtoloo almost 9 years@arkascha: According to this manual, mariadb will ask for root password at installation time: tecadmin.net/install-mariadb-10-on-ubuntu
-
arkascha almost 9 yearsI don't know much about Ubuntu, I prefer other distributions, so I cannot say anything specific. Certainly such thing is possible, I have never seen it though it probably makes sense. Anyway: that is not your issue, is it? Your issue is that your root account apparently has no password set. Did you check that inside the internal
mysql
table? If so, then just set a password and all is fine. -
mtoloo almost 9 yearsI've set the password with three different ways: using
set password
orupdate user
commands thenflush privileges
inside mysql. Usingmysqladmin
command. Usingmysql_secure_installation
. But None of them fixed the problem. I am still able to connec to mysql from command line without password, but mysql-workbench can not connect.
-
-
ρss over 8 yearsPlease add some explanation to your answer!
-
marshall almost 8 yearsMysql tries to authenticate root using plugin, not password. You need just disable plugin usage for root.
-
user1283068 over 7 yearsThis advice saved me - thanks a lot. I can't believe this isn't in the official documenation, or in any other guides that describe how to reset the root password.
-
nrvx about 7 yearsOn Ubuntu 16.04, I had an "SQL Syntax Error" using this code given by Aashish: >update user set plugin='' where User='root'; In place, I used that to overwrite authentication method : > update user set plugin="mysql_native_password";
-
deviato almost 7 yearsalso on debian 9 stretch, you have to use "update user set plugin='mysql_native_password' ..."
-
Pedru over 6 yearsexplanation can be found here
-
DeltaFlyer over 4 yearsIf you're just dabbling around in a development environment, do you need to configure mysql_secure_installation?
-
jfgiraud over 3 yearsThe ALTER USER statement was introduced in MariaDB 10.2.0.