LoginSignup
5
1

More than 3 years have passed since last update.

MySQL8: systemdでPassword Reset

Last updated at Posted at 2020-09-11

MySQLのrootパスワードリセットの情報はmysqld_safeを使ったものが多いです。
systemdを使っているとハマるので備忘録としました。

環境変数の変更からの再起動でセーフモードにする
# systemctl stop mysqld
"セーフモードの環境変数設定
# systemctl set-environment MYSQLD_OPTS="--skip-grant-tables"
"セーフモードで起動
# systemctl start mysqld
パスワードの消去
"rootでログイン
# mysql -u root
"データベースの選択
mysql> use mysql
"root権限ユーザーの表示
mysql> SELECT user, host, authentication_string FROM user;
"rootのパスワードを消去
mysql> UPDATE user SET authentication_string=null WHERE User='root';
"書き込み
mysql> FLUSH PRIVILEGES;
mysql> exit
環境変数を元に戻す。
# systemctl unset-environment MYSQLD_OPTS
MySQLの起動とパスワードの再設定
# systemctl start mysqld
"起動確認
# systemctl status mysqld
"ログイン
# mysql -u root
"パスワードの再設定
mysql> ALTER USER 'root'@'localhost' identified BY '{新パスワード}';
mysql> exit

LGTMお願いします!
モチベーションがあがります!

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1