Unable to create admin user

I’m trying to set up Nextcloud using the official Docker image and a MariaDB RDS instance on AWS.

I am supplying the following environment variables:

  • MYSQL_DATABASE = nextcloud This database does not exist yet
  • MYSQL_USER = nextcloud This is the “root” user of the RDS instance
  • MYSQL_PASSWORD The password generated for the “root” user.
  • MYSQL_HOST The hostname of the RDS instance.

To create my initial admin user, I’m supplying the following environment variables:

  • NEXTCLOUD_ADMIN_USER = oliver
  • NEXTCLOUD_ADMIN_PASSWORD A randomly generated 32 character string.

When the container starts, the setup tries to create the admin user and the database and then falls into a loop of reattempting this process:

Error while trying to create admin user: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [1044] Access denied for user 'oc_oliver'@'%' to database 'nextcloud'
Error while trying to create admin user: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [1044] Access denied for user 'oc_oliver1'@'%' to database 'nextcloud'
Error while trying to create admin user: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [1044] Access denied for user 'oc_oliver2'@'%' to database 'nextcloud'
...

I read through a lot of similar posts, like Error creating admin user, but was unable to relate them to my situation. As the error seems to be most commonly caused by the supplied user not having sufficient permissions, but I am supplying the use with the highest possible permissions, which is also the only user on the MariaDB instance. So I don’t think that’s the problem.

I also tried not supplying the NEXTCLOUD_ADMIN_USER and NEXTCLOUD_ADMIN_PASSWORD environment variables, but then I receive the same error in the web UI during setup.

When I run SHOW GRANTS FOR 'oc_oliver' on the MariaDB instance, I receive the following result:

GRANT USAGE ON *.* TO 'oc_oliver'@'%' IDENTIFIED BY PASSWORD '*7F49DDC6...'

That suggests to me that the user should have the ability to connect to the database just fine.

I then tried to use MySQL instead of MariaDB, which results in the error:

The username is already being used

I have also tried using a Postgres database instead, but that has different issues. When I provision the RDS instance with a new database nextcloud, I get the error:

Error while trying to create admin user: Failed to connect to the database: An exception occurred in driver: SQLSTATE[08006] [7] FATAL: permission denied for database "nextcloud"
DETAIL: User does not have CONNECT privilege.

Can't Install Nextcloud - pgsql CONNECT privilege suggests that you can let the installer create the database and then this would work. I tried that, but then I receive the error:

Error while trying to create admin user: Failed to connect to the database: An exception occurred in driver: SQLSTATE[08006] [7] FATAL: database "nextcloud_prod" does not exist

One of the issues here is that Nextcloud uses the ALL PRIVILEGES shortcut to grant privileges on the new database. This does not work on RDS, because the created “root” user does not have all privileges. The highest level of privileges is reserved for the management user rdsadmin, which is maintained by RDS.

Nextcloud also decides to ignore errors resulting from this shortcut GRANT query. Which makes the issue harder to analyze.

So I tried creating my admin user before running the application container, but it seems like the application refuses to use a preexisting user and just skips to trying to then create oc_oliver1 and the whole sad story starts over again.

Very disappointing.

HI I am getting same exact issue when trying to setup using RDS. I should see the supplied dbuser in config file but the occ install command gets stuck and the system does not recover and the the dbuser in the config file is oc_. I see the tables created in the database but nextcloud doesn’t work. Please help its urgent!

While I was working with Nextcloud, the issues around ECS were never fully resolved. I abandoned this project after trying to fix the issues in the setup routines for a while.