nextcloud and mariadb (both) on docker: SQLSTATE[HY000] [2002] No such file or directory

13,695

Solution 1

Just for curiousity I started playing around with the localhost-port. I chose 3307 because my host-system has a mariadb running on 3306, which I do not want to use. So altering port localhost:3307 to localhost:WXYZ - you name it gives the same error... mmmh - changeing localhost to <your host-IP>!!!

SUCCESS

Solution 2

I had to use nextcloud-mariadb:3306 as the connection string. I figured it out by running $ docker ps -a which lists the name and the port.

Solution 3

I changed localhost -> mariadb and it worked!

Share:
13,695

Related videos on Youtube

akrea
Author by

akrea

Updated on June 04, 2022

Comments

  • akrea
    akrea almost 2 years

    I've been trying to set up nextlcoud and mariadb with the linuxserver images and hit my road block when I want to get through the first run wizard of nextcloud: Error message incl. all settings of first run wizard

    Problem

    I.e. the first time wizard gives me Error while trying to create admin user: Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [2002] No such file or directory.

    Question:

    Where is that coming from and how to solve the problem?

    System

    I'm using Amahi 11 and have installed docker from the repositories. Docker verision:

      Client:
     Version:           18.09.0
     API version:       1.39
     Go version:        go1.10.4
     Git commit:        4d60db4
     Built:             Wed Nov  7 00:48:52 2018
     OS/Arch:           linux/amd64
     Experimental:      false
    
    Server: Docker Engine - Community
     Engine:
      Version:          18.09.0
      API version:      1.39 (minimum version 1.12)
      Go version:       go1.10.4
      Git commit:       4d60db4
      Built:            Wed Nov  7 00:19:08 2018
      OS/Arch:          linux/amd64
      Experimental:     false
    

    I am starting nextcloud and mariadb with docker-compose. Following the content for mariadb:

    version: '2'
      services:
        mariadb:
          image: linuxserver/mariadb
          container_name: mariadb
          environment:
            - PUID=XX
            - PGID=YYY
            - MYSQL_ROOT_USER=root
            - MYSQL_ROOT_PASSWORD=secret
            - MYSQL_DATABASE=nextcloud
          volumes:
            - <path/to/my/folder>:/config
          ports:
            - 3307:3306
          restart: unless-stopped
    

    Already tried:

    1. A lot of research, which came up empty or lead me to do the next point:
    2. So from the error info I started checking if the database actually exists:sudo docker exec -it mariadb bash. There I figured, that access to command-line with 'mysql' for root was denied because the password was not set. (mmmh... is ther something wrong with my docker-compose-file?) Anyway I corrected that one with mysql -u root -pSECRETand mysql -u root --password=SECRET. With show databases; I found no nextcloud database. (There MUST be something wrong with my docker-compose-file.) So I created it as well (create database nextcloud;). Database is now shown properly and I found it in <path/to/my/folder>. Result: No change, problem still there.
    3. I did some more editing with on my docker-compose-file:

      version: '2'
        services:
          mariadb:
            image: linuxserver/mariadb
            container_name: mariadb
            environment:
              - MYSQL_ROOT_PASSWORD=secret
              - MYSQL_DATABASE=nextcloud
              - PUID=XX
              - PGID=YYY
            volumes:
              - <path/to/my/folder>:/config
            ports:
              - 3307:3306
            restart: unless-stopped
      

      So I changed the hierarchy and eliminated the MYSQL_ROOT_USER=rootline. When restarting I can mysql -u root --password=SECRET and show the nextcloud database. YET, I am not sure, if these changes remained in the volume from my last (manual) changes. Result: Problem still there.