Reputation: 81
I've been trying to set up Nextcloud and MariaDB with the Linux server images and hit my road block when I want to get through the first run wizard of Nextcloud:
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
.
Where is that coming from and how to solve the problem?
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
A lot of research, which came up empty or lead me to do the next point:
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 -pSECRET
and 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.
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=root
line. 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.
Upvotes: 4
Views: 25687
Reputation: 11
I changed the database name(localhost:PORT -> container_name), and it worked!
By the way, the [localhost:PORT] wroked well before!
Upvotes: 1
Reputation: 23
As other answers have mentioned, the solution is don't use localhost
.
Even changing to 127.0.0.1
appears to be sufficient *(see note below)
No such file or directory
is the result of mysql attempting to connect over a local socket. This happens when either of these settings is set to localhost
:
Database host
field of the WebUIMYSQL_HOST
*Note: in the case of #2, it is not sufficient to "fix" the Database host
field in the WebUI, the environment variable MYSQL_HOST
always takes precedence.
(This is true as of NextCloud version 25.0.0.18
)
Upvotes: 1
Reputation: 878
I solved the same problem when I changed the Nexcloud MYSQL_HOST
environment parameter from localhost
to database service/image name (in my case MYSQL_HOST: mysql
) in the docker-compose.yml
version: "3.7"
services:
mysql:
image: mysql
container_name: mysql-nextcloud
restart: unless-stopped
ports:
- 3306:3306
environment:
...
volumes:
...
app:
image: nextcloud
container_name: nextcloud
restart: unless-stopped
ports:
- 80:80
links:
- mysql
volumes:
...
environment:
MYSQL_PASSWORD: ...
MYSQL_DATABASE: ...
MYSQL_USER: ...
MYSQL_HOST: mysql
Upvotes: 0
Reputation: 406
I had to use my custom server hostname, instead of localhost
. On Linux you can get it by executing the command hostname
.
Upvotes: 0
Reputation: 11
When you run Nextcloud in docker, add --link mariadb:mariadb
. You can then use mariadb
to replace localhost
Upvotes: 0
Reputation: 1245
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.
Upvotes: 4
Reputation: 81
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
Upvotes: 4