Access db failed via doctrine only

Nextcloud version: 16.0.1:
Operating system and version: Centos 7
Apache version Server version: Apache/2.4.6 (CentOS)
PHP version 7.2

I am trying to swap my database. When I use the new account details in config.php, I am presented with a blank page.
When I say occ maintenance:repair, I am told the user cannot log in.

Doctrine\DBAL\DBALException: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user ‘nextcloud’@‘localhost’ (using password: YES) in /home/xx/xx/nextcloud/lib/private/DB/Connection.php:64

There is no port in the error message (I use a non-standard port) and even if I tell it to connect to 127.0.0.1, it will still complain about localhost. So I guess the error is there.

I created a php file just to try a direct connection to the host and it works nicely. So this should not be the cause of the problems.

Any ideas?