I have docker compose app running wordpress, phpmyadmin, mysql on my development system. I successfully created the database and was able to initialize wordpress. When I click on the login link after initializing wordpress I see "Error establishing a database connection".
It seems like all I can find when searching are actual problems connecting to the database. I believe I'm connecting to the database successfully, but something happens a bit downstream which is causing the error.
The wordpress container can indeed connect to the database, but throws the error after DESCRIBE wp_users is executed. Or at least that's the last item in the mysql log. Also note phpmyadmin can connect to the database with the credentials wordpress and the password in /run/secrets/appdb-password (see docker-compose.yml).
I set up the wordpress username password as lou.king password, but it seems that would be irrelevant.
It might be relevant that I'm accessing wordpress using a port, i.e., via http://dev.localhost:8010/wp-login.php
Below are the mysql log after SET GLOBAL general_log = 'ON';, and relevant queries. This is what happens when accessing the wp-login.php view (or any other view, of course).
2025-02-17T12:18:55.580518Z 82 Connect [email protected] on using TCP/IP
2025-02-17T12:18:55.580861Z 82 Query SET NAMES utf8mb4
2025-02-17T12:18:55.581354Z 82 Query SET NAMES 'utf8mb4' COLLATE 'utf8mb4_unicode_520_ci'
2025-02-17T12:18:55.581499Z 82 Query SELECT @@SESSION.sql_mode
2025-02-17T12:18:55.581706Z 82 Query SET SESSION sql_mode='NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
2025-02-17T12:18:55.582140Z 82 Init DB wordpress
2025-02-17T12:18:55.583342Z 82 Query SELECT option_name, option_value FROM wp_options WHERE autoload IN ( 'yes', 'on', 'auto-on', 'auto' )
2025-02-17T12:18:55.584121Z 82 Query DESCRIBE wp_users
2025-02-17T12:18:55.585367Z 82 Quit
^C
sh-5.1# mysql -u wordpress -p************ wordpress
mysql: [Warning] Using a password on the command line interface can be insecure.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 85
Server version: 8.0.40 MySQL Community Server - GPL
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> describe wp_users;
+---------------------+-----------------+------+-----+---------------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+-----------------+------+-----+---------------------+----------------+
| ID | bigint unsigned | NO | PRI | NULL | auto_increment |
| user_login | varchar(60) | NO | MUL | | |
| user_pass | varchar(255) | NO | | | |
| user_nicename | varchar(50) | NO | MUL | | |
| user_email | varchar(100) | NO | MUL | | |
| user_url | varchar(100) | NO | | | |
| user_registered | datetime | NO | | 0000-00-00 00:00:00 | |
| user_activation_key | varchar(255) | NO | | | |
| user_status | int | NO | | 0 | |
| display_name | varchar(250) | NO | | | |
+---------------------+-----------------+------+-----+---------------------+----------------+
10 rows in set (0.00 sec)
mysql> select * from wp_users;
+----+------------+------------------------------------+---------------+-----------------------------+----------+---------------------+---------------------+-------------+--------------+
| ID | user_login | user_pass | user_nicename | user_email | user_url | user_registered | user_activation_key | user_status | display_name |
+----+------------+------------------------------------+---------------+-----------------------------+----------+---------------------+---------------------+-------------+--------------+
| 1 | lou.king | $P$BkSsVsE9aF0ZmWfPT8YYy4jKGh5Co41 | lou-king | [email protected] | http: | 2025-02-16 18:43:16 | | 0 | lou.king |
+----+------------+------------------------------------+---------------+-----------------------------+----------+---------------------+---------------------+-------------+--------------+
1 row in set (0.00 sec)
I'm not sure this is relevant, but here's the docker-compose.yml file
# see .env for image version env variables
# see repo/settings/environments for image version env variables for github actions
services:
wordpress:
image: wordpress:${WORDPRESS_VER}-php${PHP_VER}-fpm-alpine
restart: always
depends_on:
- db
networks:
- backend-network
- frontend-network
secrets:
- appdb-password
volumes:
- wordpress:/var/www/html
- ${VAR_LOG_HOST}:/var/log
environment:
TZ: ${TZ}
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_PASSWORD_FILE: /run/secrets/appdb-password
WORDPRESS_DEBUG: ${WORDPRESS_DEBUG}
db:
# https://github.com/docker-library/mysql/issues/275#issuecomment-636831964
image: mysql:${MYSQL_VER}
# # changed in mysql 8.4
# command: --mysql-native-password=ON
# command: '--default-authentication-plugin=mysql_native_password'
command: '--default-authentication-plugin=mysql_native_password --log_error_verbosity=3' # mysql
restart: always
secrets:
- root-password
- appdb-password
volumes:
- db:/var/lib/mysql
- ${VAR_LOG_HOST}:/var/log
networks:
- backend-network
environment:
TZ: ${TZ}
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/root-password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD_FILE: /run/secrets/appdb-password
web:
image: louking/${APP_NAME}-web:${APP_VER}
build:
context: web
args:
- NGINX_VER=${NGINX_VER}
- PHPMYADMIN_VER=${PHPMYADMIN_VER}
restart: always
networks:
- frontend-network
volumes:
- ${VAR_LOG_HOST}:/var/log
environment:
TZ: ${TZ}
ports:
- ${APP_PORT}:80
# uncomment to debug
# command: [nginx-debug, '-g', 'daemon off;']
phpmyadmin:
image: phpmyadmin:${PHPMYADMIN_VER}-fpm
restart: always
depends_on:
- db
networks:
- backend-network
- frontend-network
volumes:
- ${VAR_LOG_HOST}:/var/log
environment:
TZ: ${TZ}
PMA_ABSOLUTE_URI: http://phpmyadmin/phpmyadmin/
volumes:
db:
wordpress:
secrets:
root-password:
file: config/db/root-password.txt
appdb-password:
file: config/db/appdb-password.txt
networks:
backend-network:
frontend-network: