haiju's 開発メモ

開発に必要な情報を自分用にメモ

MariaDBでrootのパスワードをリセット

同じくCentOS7環境にインストールしているMariaDB

長らく使ってなかったのでrootのパスワードを思い出せ

なかったーwww(ΦωΦ;)

ってことで、MariaDBでrootのパスワードをリセット

する方法をメモしておく。

こちらも後ほど作業する際に、手順についてもまとめて

復習がしやすいようにする予定。

[リセット手順]

1. MySQLサーバー(MariaDB)を停止。

# systemctl stop mysqld

2. MySQLサーバーをセーフモードで起動。

# systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"

3. MySQLサーバーを起動。

# systemctl start mysqld

4. パスワード無しでrootでログイン。

mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.1.26-MariaDB MariaDB Server

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

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

5. データーベース「mysql」を選択。

MariaDB [(none)]> use mysql;
Database changed

6. パスワードを変更して反映。

MariaDB [(none)]> UPDATE user SET authentication_string=password('新パスワード') WHERE user='root';
Query OK, 4 rows affected (0.00 sec)
Rows matched: 4 Changed: 4 Warnings: 0

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

7. MySQLサーバーを停止。

8. MySQLサーバーを起動。

9. 6で変更したパスワードでログイン。

mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 10.1.26-MariaDB MariaDB Server

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

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

※エラーが出ずにログインできればOK。

※困ったこと、最初に参考サイトに上げていた情報

 だとセーフモードで起動しようとしてエラーが連発

 したため、調べ直したwww(ΦωΦ)

[参考サイト]

https://donow.jp/skillup/?p=2675

qiita.com

mtokyo.blog9.fc2.com

qiita.com

qiita.com

orebibou.com

jp.linux.com