root」タグアーカイブ

MariaDBのrootパスワードを再設定する

rootパスワードがわからなくなった場合、以下の手順でMariaDBをサービスをセーフモードで起動しパスワードを再設定することが出来る。

まずは、MariaDBのサービスを停止します。
# systemctl stop mariadb

次にセーフモードでMariaDBを起動。
# mysqld_safe –skip-grant-tables &
210119 05:49:17 mysqld_safe Logging to ‘/var/log/mariadb/mariadb.log’.
210119 05:49:17 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql

別のシェルでMariaDBのコンソールを起動
# mysql
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 5.5.68-MariaDB MariaDB Server

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)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed

rootのパスワードを更新
MariaDB [mysql]> update user set password=PASSWORD(“新しいパスワード”) where User=’root’;
Query OK, 3 rows affected (0.00 sec)
Rows matched: 3  Changed: 3  Warnings: 0

MariaDB [mysql]> exit
Bye

元のシェルで起動しているMariaDBを[Ctrl]+[C]で停止する。 元の画面が無い場合は「ps -ef | grep mysql」などでmysqlのプロセス番号を特定しkillする。