Mysql password rejected despite definitely being correct

I’ve been trying for several days to get nextcloud up and running, but I can’t get it to accept my mysql password.

I’m using docker and I’ve tried various different setups (mariadb, mysql for the database, Package nextcloud · GitHub and the official nextcloud docker one for the main instance). Whatever I do, the password is rejected and I don’t know what to try next.

Here’s my docker-compose.yml (passwords have been changed, but the character set and length is the same:

version: '2'
services:
  nextcloud:
    container_name: nextcloud
    restart: unless-stopped
    build: .
    ports:
      - 8888:8888
    volumes:
      - /containers/nextcloud/data:/var/www/html/data
      - /containers/nextcloud/config:/var/www/html/config
    depends_on:
      - nextcloud-db
    environment:
      UID: 1000
      GID: 1000
      UPLOAD_MAX_SIZE: 50G
      APC_SHM_SIZE: 128M
      OPCACHE_MEM_SIZE: 128
      CRON_PERIOD: 15m
      TZ: Europe/London

  nextcloud-db:
    container_name: nextcloud-db
    restart: unless-stopped
    image: mariadb:latest
    command: --innodb-read-only-compressed=OFF #Maria-DB fix
    environment:
      MYSQL_ROOT_PASSWORD: ZfiUjgNthly9lOaBD2oKC
      MYSQL_DATABASE: nextcloud
      MYSQL_USER: nextcloud
      MYSQL_PASSWORD: gsjjHkYGjaAsvwZyFhES
    volumes:
      - /containers/nextcloud/db:/var/lib/mysql

Dockerfile looks like this:

FROM nextcloud:latest
RUN sed -i 's/www-data:x:33:33/www-data:x:1000:1000/' /etc/passwd
RUN sed -i 's/Listen 80/Listen 8888/' /etc/apache2/ports.conf

If I connect to the nextcloud-db container (with docker exec -it $(docker-compose ps -q nextcloud-db) sh -l) and run mysql -u nextcloud -p and then paste in the password, it logs in with no issue. If I paste the exact same password into the nextcloud configuration screen, I get this:

image

I’ve tried this lots of times, with different passwords and different databases but whatever I do, it produces the same result. The logs say:

nextcloud-db    | 2022-12-04 18:30:19 17 [Warning] Access denied for user 'nextcloud'@'192.168.112.3' (using password: YES)

I’ve also tried connecting to nextcloud-db (as above) and logging into mysql as root and running:

MariaDB [(none)]> GRANT ALL ON nextcloud.* TO 'nextcloud'@'%';
Query OK, 0 rows affected (0.309 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.000 sec)

MariaDB [(none)]> SHOW GRANTS FOR nextcloud;
+----------------------------------------------------------------------------------------------------------+
| Grants for nextcloud@%                                                                                   |
+----------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO `nextcloud`@`%` IDENTIFIED BY PASSWORD '*####################' |
| GRANT ALL PRIVILEGES ON `nextcloud`.* TO `nextcloud`@`%`                                                 |
+----------------------------------------------------------------------------------------------------------+
2 rows in set (0.000 sec)

However, I still get the access denied message when I paste the password into the box on this form:

I’ve checked, double-checked and triple-checked the password is correct (and it works if I paste into the mysql password prompt and then doesn’t work if I immediately paste the same thing into the nextcloud prompt).

Can anyone tell me what I’m missing?

At first glance I don’t see any issues. Maybe strange issue exists when some invisible special character e.g. whitespace is added to your docker-compose MYSQL password

I think best option in docker setup is using environment variables for “auto-configuration”

I’m running such setup without issues long time already. Below important lines of the config. I definitely use strong MariaDB password but in general it doesn’t matter as my MariaDB is completely locked within docker…

services:
  dev-nextcloud-db:
    image: mariadb:10.5
    container_name: dev-nextcloud-db
    command: --transaction-isolation=READ-COMMITTED --log-bin=ROW
...
    env_file:
      - ./db.env

  dev-nextcloud-app:
    ....
    env_file:
      - ./nextcloud.env
      - ./db.env

and corresponding .env files like this:

> cat db.env
# maria DB container
MYSQL_HOST=dev-nextcloud-db
MYSQL_DATABASE=nextcloud
MYSQL_USER=nextcloud
MYSQL_PASSWORD=strongpassword1
MYSQL_ROOT_PASSWORD=strongpassword2