Unexpected server respose while doing caching_sha2 authの直し方

PHP

概要

  • PHP7.2の環境でWordpressが動かなくなった。
  • MySQL 8.0にあがったのが理由

解決方法

[23-Aug-2018 15:59:59 UTC] PHP Warning:  mysqli_real_connect(): Unexpected server respose while doing caching_sha2 auth: 109 in /xxxxxxxxx/wp-includes/wp-db.php on line 1531
[23-Aug-2018 16:00:09 UTC] PHP Warning:  mysqli_real_connect(): MySQL server has gone away in /xxxxxxxxx/wp-includes/wp-db.php on line 1531
[23-Aug-2018 16:00:09 UTC] PHP Warning:  mysqli_real_connect(): (HY000/2006): MySQL server has gone away in /xxxxxxxxx/wp-includes/wp-db.php on line 1531

解決するには、mysqlでパスワードのハッシュ方式を変更してあげる必要がある。

ALTER USER `username`@`localhost` IDENTIFIED WITH caching_sha2_password BY 'same password';

変更後は以下を忘れずに。

flush privileges;

これだけで完了。

しばらくしたらPHP側でcaching_sha2がサポートされるらしいので、この記事の対処は不要になるとのことですが、本家PHPのbug reportにはコメントが一切書かれていません。。。

コメント