LoginSignup
1
2

More than 1 year has passed since last update.

MySQLのrootパスワードを強制的に変更する手順

Last updated at Posted at 2022-04-10

●はじめに

MySQLのrootパスワードを忘れてしまった時の対処法を記載します。
セキュリティ的にはちょっぴり微妙なので、本番環境等では推奨してません。。

1.認証の無効化

# パスワード認証を求めない設定を入れる
vi /etc/my.cnf

# 以下を記入
[mysqld]
skip-grant-tables

# 設定の反映
systemctl restart mysqld

・[mysqld]の文字列は、デフォルトで書かれていない場合のみ記述。あれば記述不要

2.パスワードの変更

# mysqlにログイン
mysql

# 権限の反映
mysql> flush privileges;

# パスワードを任意のパスワードに変更
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';
mysql> quit

・password の部分に、自分で決めたパスワードを記述

3.設定の反映

# パスワード認証無効化の一文を削除
vi /etc/my.cnf

# 手順1で書いた「skip-grant-tables」を削除
# 設定の反映
systemctl restart mysqld

# ログイン確認
mysql -u root -p

Enter password:password
1
2
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
1
2