10.

MySQL ERROR 1820「You must reset your password」の対処(ALTER

編集
この記事の要点
  • ERROR 1820 (HY000) は MySQL ログイン直後、SQL 実行前に必ず出る「パスワード再設定要求」エラー
  • 原因: 初期パスワード / 期限切れパスワード / 管理者が password_expired 設定したアカウント
  • 対処: ALTER USER USER() IDENTIFIED BY "NewP@ssw0rd!"; でログイン中ユーザーのパスワード変更
  • validate_password プラグインのポリシー(長さ・数字・記号)を満たす必要あり
  • 一時緩和: SET GLOBAL validate_password.policy = LOW;(本番では非推奨)

このエラーの概要

MySQL に接続したあと、SHOW DATABASES; 等の最初の SQL を実行しようとするとこのメッセージが出ます:

mysql> SHOW DATABASES;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement
before executing this statement.

これはエラーというよりも、MySQL からの「パスワードを変更してから使え」という強制要求です。

発生する 3 つの状況

状況詳細
MySQL 初回インストール後MySQL 5.7+ では root の初期パスワードが password_expired = Y になっている
新規ユーザー作成時CREATE USER ... PASSWORD EXPIRE; で作成された
パスワード有効期限default_password_lifetime 設定で期限切れになった

対処1: 自分のパスワードを変更(最短解)

-- ログイン中のユーザー自身を変更
ALTER USER USER() IDENTIFIED BY 'NewP@ssw0rd!';

-- これでエラー解除、SQL が実行可能になる
SHOW DATABASES;

USER() はログイン中のユーザー名を返す関数なので、ホストを意識せず使えます。

対処2: 管理者が他ユーザーをリセット

-- root で接続
mysql -u root -p

-- 期限切れユーザーを確認
SELECT user, host, password_expired, password_last_changed
FROM mysql.user;

-- パスワード変更
ALTER USER 'app_user'@'localhost' IDENTIFIED BY 'NewP@ssw0rd!';

-- 期限切れフラグを解除(既存パスワードのまま)
ALTER USER 'app_user'@'localhost' PASSWORD EXPIRE NEVER;

-- パスワード変更要求を解除
ALTER USER 'app_user'@'localhost' PASSWORD EXPIRE DEFAULT;

FLUSH PRIVILEGES;

対処3: validate_password ポリシーを満たす

MySQL 8 では validate_password コンポーネントが既定で有効。下記の要件を満たさないと ERROR 1819(Your password does not satisfy...)が出ます:

-- 現在のポリシー確認
SHOW VARIABLES LIKE 'validate_password%';

-- 既定の MEDIUM ポリシー
-- validate_password.length            = 8     最低 8 文字
-- validate_password.mixed_case_count  = 1     大文字・小文字各 1
-- validate_password.number_count      = 1     数字 1
-- validate_password.special_char_count= 1     記号 1
-- validate_password.policy            = MEDIUM

-- ポリシーを LOW に緩和(開発環境のみ)
SET GLOBAL validate_password.policy = LOW;
SET GLOBAL validate_password.length = 6;

-- 完全に無効化(本番禁止)
UNINSTALL COMPONENT 'file://component_validate_password';

ポリシーに合うパスワード例: P@ssw0rd! / MyS3cret! / Aa1!Bb2@

対処4: パスワード有効期限の設定変更

-- 現在の既定有効期限
SHOW VARIABLES LIKE 'default_password_lifetime';
-- value = 0 なら無期限、それ以外は日数

-- 無期限に変更(my.cnf で永続化)
SET GLOBAL default_password_lifetime = 0;

-- 個別ユーザーの有効期限
ALTER USER 'app_user'@'%' PASSWORD EXPIRE INTERVAL 180 DAY;
ALTER USER 'app_user'@'%' PASSWORD EXPIRE NEVER;
ALTER USER 'app_user'@'%' PASSWORD EXPIRE DEFAULT;
# /etc/mysql/my.cnf に永続化
[mysqld]
default_password_lifetime = 0

初期 root パスワードの調べ方

# MySQL 5.7+ の Linux インストール直後の root パスワード
sudo grep 'temporary password' /var/log/mysqld.log
# 2026-05-15T12:00:00.000Z 6 [Note] [MY-010454] [Server]
#   A temporary password is generated for root@localhost: aBcD;eFg1234!

# このパスワードでログイン
mysql -u root -p
# Enter password: aBcD;eFg1234!

# 即パスワード変更(ERROR 1820 が出るのでこれをやる)
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyN3wP@ssword!';

SET PASSWORD との違い

構文対象 MySQL備考
ALTER USER ... IDENTIFIED BY5.7.6+推奨、現在の標準
SET PASSWORD = 'pw'8.0+ で 'pw' を平文指定ログイン中ユーザー専用
SET PASSWORD FOR ... = PASSWORD('pw')5.6 まで非推奨、8.x で削除済
UPDATE mysql.user SET ...5.6 以前絶対に使わない

よくあるトラブル

症状対処
ALTER USER で ERROR 1819 が出るパスワードがポリシーを満たさない、強度上げる or ポリシー緩和
変更したのにまた 1820別ホストエントリ('user'@'%' vs 'user'@'localhost')がある
パスワード再設定後すぐ期限切れPASSWORD EXPIRE NEVER を併用
レプリケーション後に発生マスターでもスレーブでも変更が必要

FAQ

Q: ALTER USER も実行できない
A: ERROR 1820 は ALTER USER だけは特別に許可されています。それ以外の SQL は実行できません。ALTER USER USER() IDENTIFIED BY 'pw'; をまず実行してください。

Q: アプリから接続すると 1820
A: アプリは ALTER USER を実行しないので、管理者が事前にパスワード期限を解除しておく必要があります。ALTER USER 'app_user'@'%' PASSWORD EXPIRE NEVER;

Q: validate_password コンポーネントが見つからない
A: MySQL 8.0 から「プラグイン」ではなく「コンポーネント」になりました。SELECT * FROM mysql.component; で確認。インストールは INSTALL COMPONENT 'file://component_validate_password';

関連エラー

  • ERROR 1819 (HY000): Your password does not satisfy the current policy requirements — ポリシー違反
  • ERROR 1862 (HY000): Your password has expired — 5.7 以前の同種エラー
  • ERROR 1396 (HY000): Operation ALTER USER failed — ユーザー存在せず
編集
Post Share
子ページ

子ページはありません

同階層のページ
  1. 1071 Specified key was too long; max key length is 767 bytes
  2. ERROR 1063 (42000): Incorrect column specifier for column '~'
  3. mysqld: Can't change dir to '...\MySQL\MySQL Server X.X\data\' (OS errno 2 - No such file or directory)
  4. Install/Remove of the Service Denied!
  5. Datetime 型が NULL に見える
  6. Warning: World-writable config file '/etc/mysql/my.cnf' is ignored
  7. ERROR 1698 (28000): Access denied for user 'root'@'localhost'
  8. Exception: Wrong MySQL configuration
  9. [Warning] TIMESTAMP with implicit DEFAULT value is deprecated.
  10. ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
  11. ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
  12. Incorrect column specifier for column 'カラム名'
  13. BLOB/TEXT column 'description' used in key specification without a key length
  14. ERROR: /bin/sh: mysql_config: コマンドが見つかりません
  15. Host '...' is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts'
  16. CSVエクスポート時に「ERROR 1045 (28000): Access denied for user 'username'@'localhost'」エラーが表示される
  17. Cannot execute statement: impossible to write to binary log since BINLOG_FORMAT = STATEMENT
  18. 1
  19. 1
  20. 1)
  21. 1
  22. 1
  23. 1
  24. 1
  25. 1
  26. 1
  27. 1
  28. 1
  29. 1
  30. 1
  31. 1
  32. 1
  33. 1"'`--
  34. 1
  35. 1
  36. 1
  37. 1
  38. 1
  39. 1
  40. 1
  41. 1
  42. 1
  43. 1)
  44. 1
  45. 1
  46. 1
  47. 1
  48. 1
  49. 1
  50. 1
  51. 1
  52. 1
  53. 1"'`--
  54. 1
  55. 1
  56. SQLSTATE[22007]: Invalid datetime format: 1366 Incorrect string value: ~