Installation problem with remote database


I have a problem to install Nextcloud 17 by using a remote database. Following scenario:

2 Systems installed with Debian 10, current updates.

Database Server []

  • MariaDB - current version of Debian GNU/Linux 10
  • There are 2 users root@localhost and dbadm@
  • Database is listening on non-standard port 5678
  • The DBA was created with “CREATE USER ‘dbadm’@‘’ IDENTIFIED BY ‘foobar’;”
  • The privileges were changed to “GRANT ALL PRIVILEGES ON *.* TO ‘dbadm’@‘’ IDENTIFIED BY PASSWORD ‘*abcdef…’ WITH GRANT OPTION;”
  • The DBA is not using any plugin

WWW-Server []

  • Apache 2 - current version of Debian GNU/Linux 10
  • From this server the following works:
    • telnet 5678
    • mysql -h -P 5678 -u dbadm -p
    • mysql> CREATE DATABASE nextcloud;
    • mysql> CREATE USER oc_admin IDENTIFIED BY ‘oc-foobar’;
    • mysql> GRANT ALL PRIVILEGES ON nextcloud.* TO ‘oc_admin’@’%’;

But, it’s not possible to install nextcloud over the GUI or CLI. I got the following error message:

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

With the CLI:
su - www-data
cd /opt/nextcloud
./occ maintenance:install --database=mysql --database-name=nextcloud --database-host= --database-user=dbadm --database-pass=foobar --admin-user=admin --admin-pass=oc-foobar

BTW: “–database-host= --database-port=5678” doesn’t work.

Where’s my mistake?

The displayed access denied error explains all. By default a database only accepts connection on the loopback device (localhost) or the database socket. If you want to access the database over the network you have to allow this access by creating the required user.

You can use the following command to display all existing database accesses:

mysql -D mysql -e "select user,host,db from mysql.db;"

Here you find information about how to set-up a remote database access: