MariaDB mysql_secure_installation実行時に「ERROR 1698 (28000): Access denied for user ‘root’@’localhost’」が発生

MariaDB mysql_secure_installation実行時に「ERROR 1698 (28000): Access denied for user ‘root’@’localhost’」が発生

MariaDBでmysql_secure_installationを実行してrootのパスワードを作成しようとしても作成できなかったため、その際の対処法を記述してます。

環境

  • OS Ubuntu 20.10
  • MariaDB 10.3.25-MariaDB-0ubuntu1 Ubuntu 20.10

エラー全文

インストール後に、

sudo apt install mariadb-server  mariadb-client

「mysql_secure_installation」を実行時に発生

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):
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
Enter current password for root (enter for none):
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
Enter current password for root (enter for none):
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
Enter current password for root (enter for none):
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
Enter current password for root (enter for none):
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
Enter current password for root (enter for none):

何度ENTERキーを押下しても、エラーが発生

対処法

sudoでログインしてパスワードを作成する

sudo mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY "ここにパスワードを設定";

これでログインできるようになりました。

mysql -u root -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 64
Server version: 10.3.25-MariaDB-0ubuntu1 Ubuntu 20.10

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.