Nextcloud+MariaDB - MySQL Server has gone away/Error while trying to create admin user

version: '3'

services:

  db:
    image: mariadb
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    container_name: mariadb
    networks:
      - nextcloud_network
    volumes:
      - ${HOME}/Services/MariaDB:/var/lib/mysql
      - /etc/localtime:/etc/localtime:ro
    user: 1000:1000 
    environment:
      - MYSQL_ROOT_PASSWORD=toor
      - MYSQL_PASSWORD=mysql
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    restart: always

  app:
    image: nextcloud:latest
    container_name: nextcloud
    networks:
      - nextcloud_network
    depends_on:
      - db
    user: 1000:1000
    ports:
      - 8080:80
    environment:
      - MYSQL_HOST=db
      - MYSQL_PASSWORD=mysql
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    sysctls:
      - net.ipv4.ip_unprivileged_port_start=0 # Allow an unprivileged user to listen on any port (https://github.com/nextcloud/docker/issues/359)
    volumes:
      - ${HOME}/Services/Nextcloud:/var/www/html
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped

networks:
  nextcloud_network:

This is my docker-compose, running on ubuntu 18.04 LTS. ${Home}/Services is an NFS mount, which is why I need user: 1000:1000

The containers create successfully, but I can’t actually complete the initial setup wizard.

I get one of two errors.
Error while trying to create admin user: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2006] MySQL server has gone away

Error while trying to create admin user: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2002] Connection refused

I tried getting rid of the docker network, and just use host networking, but nothing changed. I am sure I am doing something wrong, I just don’t know what that would be. The compose file looks good to me.

Any advice? Thanks!!!

Please have a look at the mysql logs.

If you run this setup without the volumes (just using temporary container volumes) does it work?

It seems like it should be a working setup, but you’ve changed quite a few settings too. Try cutting it down as bare bones as you can (you can use line comments) and docker-compose down/up just to test and then incrementally add things back.

Can you access the mariadb server via the mysql command on the cli? Is the service started?

2019-09-22 14:06:36 0 [Note] mysqld (mysqld 10.4.8-MariaDB-1:10.4.8+maria~bionic) starting as process 1 ...
2019-09-22 14:06:36 0 [Warning] You need to use --log-bin to make --binlog-format work.
2019-09-22 14:06:36 0 [Note] InnoDB: Using Linux native AIO
2019-09-22 14:06:36 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2019-09-22 14:06:36 0 [Note] InnoDB: Uses event mutexes
2019-09-22 14:06:36 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2019-09-22 14:06:36 0 [Note] InnoDB: Number of pools: 1
2019-09-22 14:06:36 0 [Note] InnoDB: Using SSE2 crc32 instructions
2019-09-22 14:06:36 0 [Note] mysqld: O_TMPFILE is not supported on /tmp (disabling future attempts)
2019-09-22 14:06:36 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
2019-09-22 14:06:36 0 [Note] InnoDB: Completed initialization of buffer pool
2019-09-22 14:06:36 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2019-09-22 14:06:36 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
2019-09-22 14:06:36 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2019-09-22 14:06:36 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2019-09-22 14:08:10 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2019-09-22 14:08:10 0 [Note] InnoDB: 10.4.8 started; log sequence number 140169; transaction id 21
2019-09-22 14:08:10 0 [Note] Plugin 'FEEDBACK' is disabled.
2019-09-22 14:08:10 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2019-09-22 14:08:10 0 [Note] Server socket created on IP: '::'.
2019-09-22 14:08:10 0 [Note] InnoDB: Buffer pool(s) load completed at 190922 14:08:10
2019-09-22 14:08:10 0 [Warning] 'user' entry 'root@d4c4779dd612' ignored in --skip-name-resolve mode.
2019-09-22 14:08:10 0 [Warning] 'user' entry '@d4c4779dd612' ignored in --skip-name-resolve mode.
2019-09-22 14:08:10 0 [Warning] 'proxies_priv' entry '@% root@d4c4779dd612' ignored in --skip-name-resolve mode.
2019-09-22 14:08:10 0 [Note] Reading of all Master_info entries succeeded
2019-09-22 14:08:10 0 [Note] Added new Master_info '' to hash table
2019-09-22 14:08:10 0 [Note] mysqld: ready for connections.
Version: '10.4.8-MariaDB-1:10.4.8+maria~bionic'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
2019-09-22 14:18:07 8 [Warning] Aborted connection 8 to db: 'unconnected' user: 'unauthenticated' host: '192.168.32.3' (This connection closed normally without authentication)

Hi,

I’m facing the same problem. The funny thing is, that I was developing the docker-compose.yml on my Manjaro PC and everything was alright. When I moved it on an Ubuntu 18.04.03 Server the problem came up. The only thing I changed was the exposed IP-Adress of the Traefik Reverse Proxy:


version: '3.7'

volumes:
  nc_nextcloud:
  nc_apps:
  nc_config:
  nc_data:
  nc_db:

services:
  traefik:
    image: traefik:latest
    container_name: traefik
    command: --providers.docker
    restart: always
    ports:
      - 192.168.x.x:80:80
      - 192.168.x.x:443:443
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./static.yml:/etc/traefik/traefik.yml
      - ./dynamic.yml:/etc/traefik/dynamic/dynamic.yml
      - ./acme.json:/etc/traefik/acme/acme.json

    environment:
      - "TZ=Europe/Berlin"
      
  db:
    image: mariadb
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW --wait_timeout=28800
    restart: always
    volumes:
      - nc_db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=xxx
      - MYSQL_PASSWORD=xxx
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - NETWORK_ACCESS=internal

  nextcloud:
    image: nextcloud
    ports:
      - 8081:80
    links:
      - db
    environment:
      MYSQL_HOST: db
      MYSQL_PASSWORD: xxx
      MYSQL_DATABASE: nextcloud
      MYSQL_USER: nextcloud
    labels:
      - "traefik.backend=nextcloud"
      - traefik.http.routers.wolke.rule=Host(`wolke.aaa.bb`)
      - "traefik.http.routers.wolke.tls.certResolver=default"
      - "traefik.http.routers.wolke.tls=true"
      - "traefik.port=8081"
    depends_on: 
      - db
    volumes:
      - nc_nextcloud:/var/www/html
      - nc_apps:/var/www/html/custom_apps
      - nc_config:/var/www/html/config
      - nc_data:/var/www/html/data
    restart: always

Is there anybody out there with a hint?

cheers, Hansi

Edit: I just tried without the Reverse Proxy: same result

so I did some more troubleshooting.

The problem is related to my NFS mounts and their permissions.

I believe when both containers start up and initialize, they run as root. Forcing them to 1000:1000, works to give them NFS access, but then the container init can’t finish since it no longer has root access.

Hello,

I also did troubleshooting and found out, that you need (a lot of) patience.
For a reason I don’t know the docker-entrypoint.sh needs a long time to complete (it took 14 minutes for me).
It hangs at:
mysql_tzinfo_to_sql /usr/share/zoneinfo | sed ‘s/Local time zone must be set–see zic manual page/FCTY/’ | “${mysql[@]}” mysql

When the script has finished, MariaDB is restarted and works for me. Please don’t ask me for the reason of this behaviour…

Cheers, Hansi

Hello, has the same problem though connect from console to mariadb from php -r successfully:

[root@nextcloud config]# php -r '
>
> $servername = "nextcloud";
> $username = "root";
> $password = "";
>
> // Create connection
> $conn = new mysqli($servername, $username, $password);
>
> // Check connection
> if ($conn->connect_error) {
>     die("Connection failed: " . $conn->connect_error);
> }
> echo "Connected successfully";
>
> '
Connected successfully[ro
[root@nextcloud config]#

… in …nextcloud.log

"message":{"Exception":"Doctrine\\DBAL\\DBALException","Message":"Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2006] MySQL server has gone away"

From config.php

‘dbtype’ => ‘mysql’,
‘dbhost’ => ‘127.0.0.1:3306’,
‘dbname’ => ‘nextcloud’,
‘dbuser’ => ‘root’,
‘dbpassword’ => ‘’,
‘dbtableprefix’ => ‘oc_’,
‘installed’ => false,

[root@nextcloud config]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

Server version: 5.5.64-MariaDB MariaDB Server

[root@nextcloud config]# cat /etc/my.cnf
[server]
#skip-name-resolve
bind-address = 0.0.0.0
innodb_buffer_pool_size = 128M
innodb_buffer_pool_instances = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 32M
innodb_max_dirty_pages_pct = 90
query_cache_type = 1
query_cache_limit = 2M
query_cache_min_res_unit = 2k
query_cache_size = 64M
tmp_table_size= 64M
max_heap_table_size= 64M
slow-query-log = 1
slow-query-log-file = /var/log/mysql/slow.log
long_query_time = 1

[client-server]
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mariadb.conf.d/

[client]
default-character-set = utf8mb4

[mysqld]
general_log = on
general_log_file=/var/log/mysql/mysql-general.log
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
transaction_isolation = READ-COMMITTED
binlog_format = ROW
innodb_large_prefix=on
innodb_file_format=barracuda
innodb_file_per_table=1
log-error = /var/log/mysql/mysqld.error.log
log-bin=/var/log/mysql/mysql-bin.log
wait_timeout=600
max_allowed_packet=64M

Could anybody help?

Hi! did anybody found a solution to this issue, I am having the same problem.
Thanks

I did this for both admin and nextcloud users and I got through:
mysql
CREATE USER ‘admin’@’%’ IDENTIFIED BY ‘AdMiNpAsSwOrD’;
GRANT ALL PRIVILEGES ON . TO ‘admin’@’%’ WITH GRANT OPTION;
FLUSH PRIVILEGES;
exit;

From Here:
https://www.delixirpro.com/blog/2020/01/04/mariadb-access-denied-for-user-rootlocalhost/