wordpressとmysqlを構築していくときに幾つかエラーに遭遇したので、ここにまとめておきます。
- エラー達
- エラー①:MySQL Connection Error: (2002) php_network_getaddresses: getaddrinfo failed: Name or service not known
- エラー②:MySQL Connection Error: (2054) Server sent charset unknown to the client. Please, report to the developers
- エラー③:MySQL Connection Error: (2054) The server requested authentication method unknown to the client
エラー達
エラー①: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
以下のサイトを参考にしました。

以下のように書いてありました。
Some answers recommended changing the server charset back to
utf8
fromutf8mb4
, 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では対応されていない場合に発生するようです。
参考は以下。

なので、wordpressのバージョンが古いと発生する可能性があります。
僕はwordpressのバージョンを上げたら直りました。