LoginSignup
7
10

More than 5 years have passed since last update.

[MySQL]MySQL接続エラー(mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication)

Last updated at Posted at 2016-02-02

[MySQL]MySQL接続エラー(mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication)

事象

  • PHPから外部DBであるMySQLへの接続でエラーが発生

確認内容

  • 接続先情報について何度も確認したが問題ない
  • 別サーバからの接続テストでMySQLへ接続できることを確認

エラー内容をもうよく一度見る

英文

mysqlnd cannot connect to MySQL 4.1+ using the old insecure authentication.
Please use an administration tool to reset your password with the command SET PASSWORD = PASSWORD('your_existing_password').
This will store a new, and more secure, hash value in mysql.user.
If this user is used in other scripts executed by PHP 5.2 or earlier you might need to remove the old-passwords flag from your my.cnf file

Google翻訳

mysqlndは、古い安全でない認証を使用して、 4.1以降のMySQLに接続することはできません。
コマンドSET PASSWORD = PASSWORD ( ' your_existing_password ')を使用してパスワードをリセットするには、管理ツールを使用してください。
これはにmysql.userに新しい、より安全、ハッシュ値を格納します。
このユーザーは、 PHP 5.2で実行される他のスクリプトで使用またはそれ以前のバージョンされている場合は、あなたのmy.cnfファイルから古いパスワードフラグを削除する必要がある場合があります

解釈

  • 今のmysqlndで接続できないってことか?

調べた

MySQL 4.1+ using the old insecure authenticationで検索

色々出てきましたよ

原因

  • mysqlndはMySQLの古い形式のパスワードをサポートしなくなった
    • 古い形式 : ハッシュ値の長さが16バイト

解決方法

  • 接続したいユーザーのパスワードを「41バイトハッシュ」で再作成する

やり方

  • 「my.cnf」に「old_password=1」が設定されていないMySQLに接続
  • パスワードの41バイトハッシュを作る(以下コマンド)
SELECT PASSWORD('abcdef');
# *C2D24DCA38E9E862098B85BF0AB35CAA52803797
  • パスワードを更新する
SET PASSWORD FOR testuser@'%' = '*C2D24DCA38E9E862098B85BF0AB35CAA52803797';

これで新しいパスワードがセットされた

再度接続したところ問題なく接続できた!!

本当は

  • 本当は「my.cnf」の「old_password=1」を「old_password=0」にする必要がある
  • その後mysqlを再起動
  • 次回から作成するユーザーは「41バイトハッシュ」されたパスワードになる
    • 既存のユーザーパスワードは「16バイトハッシュ」されたパスワードのまま

だが本番稼働しているので、そんなことできない!

なので今回のような解決方法を取りました。
以上です。

7
10
1

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
7
10