自作Helm Chartのwordpress×mysqlで悶絶したら確認すること(案の定k8sが上手くいかない #7)

スポンサーリンク
個人開発
スポンサーリンク

wordpressとmysqlを構築していくときに幾つかエラーに遭遇したので、ここにまとめておきます。

エラー達

エラー①:MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known

Warning: mysqli::mysqli(): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22

Warning: mysqli::mysqli(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: Name or service not known in - on line 22

MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known

これは、serviceのnameの問題。

今回の場合、hostでpodの名前を指定しようとして失敗しています。

wordpressのdeployment.ymlの以下の部分ですね。ハイライトのところ。

---

apiVersion: apps/v1
kind: Deployment
metadata:
  name: test-wordpress
  labels:
    app: test-wordpress
  namespace: wp
spec:
  selector:
    matchLabels:
      app: test-wordpress
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: test-wordpress
    spec:
      containers:
      - image: wordpress:6.7.0-apache
        name: wordpress-container
        env:
        - name: WORDPRESS_DB_HOST
          value: test-wp-mysql
・・・【略】・・・

ここはmysqlのserviceの名前を指定する必要があります。

エラー②:MySQL Connection Error: (2054) Server sent charset unknown to the client. Please, report to the developers

Warning: mysqli::mysqli(): Server sent charset (255) unknown to the client. Please, report to the developers in - on line 22

Warning: mysqli::mysqli(): (HY000/2054): Server sent charset unknown to the client. Please, report to the developers in - on line 22

MySQL Connection Error: (2054) Server sent charset unknown to the client. Please, report to the developers

以下のサイトを参考にしました。

SQLSTATE[HY000] [2054] Server sent charset unknown to the client. Please, report to the developers
I am trying to create a login system in laravel. I've updated env. file with a database called kokodb. However, when I run this code 'php artisan migrate' in c

以下のように書いてありました。

Some answers recommended changing the server charset back to utf8 from utf8mb4, but that is a bad idea. utf8 doesn’t support the full range of valid unicode characters, so trying to save a string that contains certain characters (like some sets of emoji) will cause a database error. It is much better to simply upgrade PHP to a more recent version.

deployment.yamlの以下のハイライトのところを追加して解決。

apiVersion: apps/v1 # for versions before 1.9.0 use apps/v1beta2
kind: Deployment
metadata:
  name: test-wp-mysql
  labels:
    app: test-wordpress
  namespace: ingress-nginx
spec:
  selector:
    matchLabels:
      app: test-wordpress
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: test-wordpress
    spec:
      containers:
      - image: 'mysql:8'
        name: test-wp-mysql
        args:
          - --character-set-server=utf8mb4
          - --collation-server=utf8mb4_unicode_ci
        env:
・・・【略】・・・

エラー③:MySQL Connection Error: (2054) The server requested authentication method unknown to the client

Warning: mysqli::mysqli(): The server requested authentication method unknown to the client [caching_sha2_password] in - on line 22

Warning: mysqli::mysqli(): (HY000/2054): The server requested authentication method unknown to the client in - on line 22

MySQL Connection Error: (2054) The server requested authentication method unknown to the client

wordpressのバージョンが原因。

バージョンが古いと発生することがあります。

今回はmysqlの8を使っています。

しかし、認証方式は「caching_sha2_password」でwordpress側のphpでは対応されていない場合に発生するようです。

参考は以下。

FuelPHPでのMySQL接続時にThe server requested authentication method unknown to the client [caching_sha2_password] となった場合に対処してみた - Qiita
概要FuelPHPでMySQLに接続時、掲題のエラーが発生した場合の対応法です。環境MySQL v8.0PHP 7.3.12エラー事由MySQL8.0でのデフォルトの認証方式は「cach…

なので、wordpressのバージョンが古いと発生する可能性があります。

僕はwordpressのバージョンを上げたら直りました。

タイトルとURLをコピーしました