mariadbのルートのパスワードを忘れた。 | Aqua Informatics
はじめに01:25 午後 kimi@ryzen9-MS-7C37:~$ mysql -u root -pEnter password: ERROR 1698 (28000): Access denied for user 'root'@'l...
はじめに
mysql -u root -p
Enter password:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
rootのパスワードを忘れたのでリセットする。よく忘れるので、ここに記録しとこ
パスワード無しでログインする
–skip-grant-tablesオプションで起動する。特権テーブルのチェックが無効化されて、すべてのユーザーに特権が与えられた状態(パスワードなし)でログイン可能になる。
sudo systemctl stop mariadb
sudo systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
sudo systemctl start mariadb
入れた
mysql -u root
sudo mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 33
Server version: 10.6.16-MariaDB-0ubuntu0.22.04.1 Ubuntu 22.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)]> alter user 'root'@'localhost' identified by '********'
;ERROR 1290 (HY000): The MariaDB server is running with the --skip-grant-tables option so it cannot execute this statement
あ、特権テーブルを無効化しているので、通常の方法ではパスワード変更は無効、エラーとなる。flush privileges;で特権情報を再読込して、パスワードを変更。
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> alter user 'root'@'localhost' identified by '********';
Query OK, 0 rows affected (0.001 sec)
後処理
mariadbの起動オプションをもとに戻して再起動。新しいパスワードでログインできた。
sudo systemctl stop mariadb
sudo systemctl unset-environment MYSQLD_OPTS
sudo systemctl start mariadb
sudo mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.6.16-MariaDB-0ubuntu0.22.04.1 Ubuntu 22.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)]>
カテゴリーLinux
コメント