Unraid: Set up Nextcloud with Mariadb

Nextcloud- Fixing your MariaDB connection Error in Unraid

Following on from my post on how to set up external drives in Unraid, I wanted to write up my solution for getting around a persistent error I kept running into when trying to install Nextcloud.

The Problem

I followed the tutorials online to the letter. I created a share on the array called nextcloud. I installed Mariadb, set my various passwords in the container and ran the container. I deleted the bottom variable as I didn’t want to use it.

Setup for Mariadb
Setup for Mariadb

Mariadb fired up with no errors in the logs. I then went to install Nextcloud. I used the linuxserver image (my preferred repository), changed the port number from 443 to 444 (Unraid needs 443), and fired her up.

Setup for Nextcloud
Setup for Nextcloud

I entered a new username and password (mindful to keep them different to the database credentials we set up in Mariadb). I then clicked on the database part but when it came to connecting to the database, I was continually met with this error:

Error while trying to create admin user: Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [1045] Access denied for user ‘…..’@’localhost’ (using password: YES)

Troubleshooting:

  • Changed every credential in Mariadb and nextcloud repeatedly, including removing non-alphanumeric characters
  • Nuked both images and started over (including deleting the directories out of /appdata )
  • I tried localhost:3306, 127.0.0.1:3306, my.server.ip.address:3306, nothing would connect
  • I worked through countless varieties of combos of the Mariadb credentials to no-avail.

Solution:

I started to look online for the answer, it seems I wasn’t the only one having this problem. I saw people recommending going into the shell of the Mariadb container and manually configuring a new user, but that all seemed like hardwork. Particularly as we already had the variables set in Unraid.

I decided to try and look into the database itself, and for that I needed adminer:

  1. Go to the Apps page and download and install adminer. I left everything as standard aside from changing the port.
    Installing Adminer in Community Apps
    Installing Adminer in Community Apps

    Set up for adminer
    Set up for adminer
  2. Ensure Mariadb is running, and then from the adminer webpage, select the database to connect to. Note: here you can connect to your nextcloud database as the user, or you can connect to Mariadb as root. I opted for the second. Username is root, and password is whatever you configured in the mariadb container (“MYSQL_ROOT_PASSWORD”). Enable permanent login at the bottom to save the credentials for next time (a list of your logins will save to the left).
  3. On a successful login, you should see a list of databases… You can ignore all of them aside from the nextcloud database you set up (yours might be named differently).
  4. Enter your nextcloud database and select Privileges (top right).

    Selecting the Privileges option (top right)
    Selecting the Privileges option (top right)
  5. You should see your user at the top. Click on Edit.

    Editing your user's privileges in MariaDB
    Editing your user’s privileges in MariaDB
  6. I toggled off ‘All privileges’ and then toggled it back on. Hit save at the bottom. Now try to connect the database to Nextcloud.

For me, it connected straight away. For local host, at the bottom of the config screen, I literally just put in the address of the mariadb container, i.e. 192.x.x.x:3306 (I didn’t bother with http or https). After a minute or so deploying, I was staring at the Nextcloud login screen.

Installing the Nextcloud Client on Windows

I decided to use Chocolatey for this. If you’re not using choco, you need to be!

See here for more details. Installation was as simple as:

choco install nextcloud-client -y

Within 30 seconds, I was staring at my share in Windows.

Nextcloud installed in windows
Nextcloud installed in windows

 

After thought

Am I exactly sure what happened initially to stop me from making a successful connection? No. It looks to me like the database password that we set up in the container template for some reason didn’t take properly. Adminer seemed to allow me to essentially force the password through. Maybe this is a bug, or maybe by design. Either way, I’m now looking at a successful Nextcloud installation.

Successful Nextcloud Installation
Successful Nextcloud Installation

If anyone has any other ideas or explanations, I’m all ears. Better yet, why not join us on facebook to help share any other solutions or tips and tricks.

https://www.facebook.com/groups/386238285944105

If you’re considering a renovation and looking at the structured wiring side of things, or maybe you just want to support the blog, have a look below at my smarthome book, it’s available in all the usual places (including paperback).

The Smarthome Book
The Smarthome Book

Comments

  1. Glad I wasn’t the only one running into this issue, but still have not solved it. I am using the same login for adminer that I was for nextcloud’s mariadb setup. It makes sense, if i was not allowed access to the database in nextcloud using the root username and password I just created in the mariadb container, why would adminer be any different. Any other ideas?

    Thanks,
    Cory

Leave a Reply