Installation problem with remote database

Hi,

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 [4.3.2.1]

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

WWW-Server [1.2.3.4]

  • Apache 2 - current version of Debian GNU/Linux 10
  • From this server the following works:
    • telnet 4.3.2.1 5678
    • mysql -h 4.3.2.1 -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’@‘1.2.3.4’ (using password: YES)

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

BTW: “–database-host=4.3.2.1 --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: