[MDEV-11589] Cannot log in to MariaDB as root, after running mysql_secure_installation Created: 2016-12-17  Updated: 2016-12-21  Resolved: 2016-12-21

Status: Closed
Project: MariaDB Server
Component/s: Authentication and Privilege System
Affects Version/s: 10.0.28
Fix Version/s: N/A

Type: Bug Priority: Blocker
Reporter: AM Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: None
Environment:

Ubuntu 16.04 LTS - latest updates applied



 Description   

I cannot log in to Maria DB after having created the root password.

I have a new environment and had installed mariadb a couple weeks back but never got round to using it. I thought, maybe, I forgot the password. So I've completely removed it and re-installed it but it is the same issue. Cannot log in as root. JournalCtl -xe reports no errors.

user@hostname:~$ sudo apt-get remove --purge mariadb-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  mariadb-server-10.0 mariadb-server-core-10.0
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  mariadb-server*
0 to upgrade, 0 to newly install, 1 to remove and 5 not to upgrade.
After this operation, 61.4 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 218086 files and directories currently installed.)
Removing mariadb-server (10.0.28-0ubuntu0.16.04.1) ...
user@hostname:~$ sudo apt-get remove --purge mariadb-server*
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'mariadb-server-core-5.5' for glob 'mariadb-server*'
Note, selecting 'mariadb-server-5.5' for glob 'mariadb-server*'
Note, selecting 'mariadb-server-core-10.0' for glob 'mariadb-server*'
Note, selecting 'mariadb-server-10.0' for glob 'mariadb-server*'
Note, selecting 'mariadb-server' for glob 'mariadb-server*'
Package 'mariadb-server-5.5' is not installed, so not removed
Package 'mariadb-server-core-5.5' is not installed, so not removed
Package 'mariadb-server' is not installed, so not removed
The following packages will be REMOVED:
  mariadb-server-10.0* mariadb-server-core-10.0*
0 to upgrade, 0 to newly install, 2 to remove and 5 not to upgrade.
After this operation, 89.9 MB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 218083 files and directories currently installed.)
Removing mariadb-server-10.0 (10.0.28-0ubuntu0.16.04.1) ...
Purging configuration files for mariadb-server-10.0 (10.0.28-0ubuntu0.16.04.1) ...
Removing mariadb-server-core-10.0 (10.0.28-0ubuntu0.16.04.1) ...
Processing triggers for man-db (2.7.5-1) ...
user@hostname:~$ ls /var/lib/mysql/
aria_log.00000001  ibdata1      multi-master.info   performance_schema
aria_log_control   ib_logfile0  mysql
debian-10.0.flag   ib_logfile1  mysql_upgrade_info
user@hostname:~$ sudo rm -rf /var/lib/mysql/
user@hostname:~$ sudo rm -rf /etc/mysql/
conf.d/          mariadb.cnf      my.cnf           
debian.cnf       mariadb.conf.d/  my.cnf.fallback  
user@hostname:~$ sudo rm -rf /etc/mysql/
conf.d/          mariadb.cnf      my.cnf           
debian.cnf       mariadb.conf.d/  my.cnf.fallback  
user@hostname:~$ sudo rm -rf /etc/mysql/
user@hostname:~$ sudo apt-get install mariadb-server
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  mariadb-server-10.0 mariadb-server-core-10.0
Suggested packages:
  mailx mariadb-test tinyca
The following NEW packages will be installed:
  mariadb-server mariadb-server-10.0 mariadb-server-core-10.0
0 to upgrade, 3 to newly install, 0 to remove and 5 not to upgrade.
Need to get 0 B/8,617 kB of archives.
After this operation, 89.9 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Preconfiguring packages ...
Selecting previously unselected package mariadb-server-core-10.0.
(Reading database ... 217906 files and directories currently installed.)
Preparing to unpack .../mariadb-server-core-10.0_10.0.28-0ubuntu0.16.04.1_amd64.deb ...
Unpacking mariadb-server-core-10.0 (10.0.28-0ubuntu0.16.04.1) ...
Selecting previously unselected package mariadb-server-10.0.
Preparing to unpack .../mariadb-server-10.0_10.0.28-0ubuntu0.16.04.1_amd64.deb ...
Unpacking mariadb-server-10.0 (10.0.28-0ubuntu0.16.04.1) ...
Selecting previously unselected package mariadb-server.
Preparing to unpack .../mariadb-server_10.0.28-0ubuntu0.16.04.1_all.deb ...
Unpacking mariadb-server (10.0.28-0ubuntu0.16.04.1) ...
Processing triggers for man-db (2.7.5-1) ...
Processing triggers for systemd (229-4ubuntu13) ...
Processing triggers for ureadahead (0.100.0-19) ...
Setting up mariadb-server-core-10.0 (10.0.28-0ubuntu0.16.04.1) ...
Setting up mariadb-server-10.0 (10.0.28-0ubuntu0.16.04.1) ...
Setting up mariadb-server (10.0.28-0ubuntu0.16.04.1) ...
Processing triggers for systemd (229-4ubuntu13) ...
Processing triggers for ureadahead (0.100.0-19) ...
user@hostname:~$ sudo my
myisamchk                   mysql_embedded
myisam_ftdump               mysql_find_rows
myisamlog                   mysql_fix_extensions
myisampack                  mysqlhotcopy
my_print_defaults           mysqlimport
mysql                       mysql_install_db
mysqlaccess                 mysqloptimize
mysqladmin                  mysql_plugin
mysqlanalyze                mysqlrepair
mysqlbinlog                 mysqlreport
mysqlbug                    mysql_secure_installation
mysqlcheck                  mysql_setpermission
mysql_convert_table_format  mysqlshow
mysqld                      mysqlslap
mysqld_multi                mysql_tzinfo_to_sql
mysqld_safe                 mysql_upgrade
mysqldump                   mysql_waitpid
mysqldumpslow               mysql_zap
user@hostname:~$ sudo mysql_secure_installation 
 
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
 
In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
 
Enter current password for root (enter for none): 
OK, successfully used password, moving on...
 
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
 
Set root password? [Y/n] Y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!
 
 
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
 
Remove anonymous users? [Y/n] Y
 ... Success!
 
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
 
Disallow root login remotely? [Y/n] Y
 ... Success!
 
By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
 
Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
 
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
 
Reload privilege tables now? [Y/n] Y
 ... Success!
 
Cleaning up...
 
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
 
Thanks for using MariaDB!

user@hostname:~$ mysql -u root -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
user@hostname:~$ mysql -u root -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
user@hostname:~$ mysql -u root -p
Enter password: 
ERROR 1698 (28000): Access denied for user 'root'@'localhost'



 Comments   
Comment by Elena Stepanova [ 2016-12-17 ]

10.0.28-0ubuntu0.16.04.1 are packages provided by Ubuntu. Recently they switched to Unix socket authentication for the local root as a default. Basically, it means you have to be root in the system if you want to connect as root to the database. You should be able to connect as

sudo mysql -uroot

When you are connected, run

select user, host, password, plugin from mysql.user;

You should see something like

MariaDB [(none)]> select user, host, password, plugin from mysql.user;
+------+-----------+-------------------------------------------+-------------+
| user | host      | password                                  | plugin      |
+------+-----------+-------------------------------------------+-------------+
| root | localhost | *94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29 | unix_socket |
+------+-----------+-------------------------------------------+-------------+
1 row in set (0.00 sec)

If you don't want such authentication, you can remove unix_socket from the plugin field, run flush privileges, then it should work as before, assuming you already have the right password.

Please let us know if it helps to solve the problem, I'll keep the report open until then.

Comment by AM [ 2016-12-18 ]

Thank you.

I did also find this thread helpful to solve this: https://ubuntuforums.org/showthread.php?t=2275033

shell$ sudo mysql -u root

[mysql] use mysql;
[mysql] update user set plugin='' where User='root';
[mysql] flush privileges;
[mysql] \q

I will close now. Could you please change status to closed?

Comment by Daniel Black [ 2016-12-21 ]

Of course changing this could break log rotate and other aspects of automated/package database changes.

Granting SUPER privs to your own unix user (via unix_socket) in MariaDB could be less intrustive.

Generated at Thu Feb 08 07:51:07 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.