Installation cant access mariadb - bug

Hi, I had to reset my whole Nextcloud instance, because I whyever couldn’t access nextcloud after 3 years of using 2FA …
Long story short, I came to the point where I dropped the Database and want to begin from new.
Unfortunately I cannot login in to mysql with my nextcloud DB user. However I can totally login to mysql using this user and password.

This seems to me like a bug

See my console output:

root@ncloud:/var/www/nextcloud# mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 111
Server version: 10.3.36-MariaDB-0+deb10u2-log Raspbian 10

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> CREATE USER 'ncdb'@'localhost' IDENTIFIED BY 'dbpass';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> GRANT ALL PRIVILEGES ON nextcloud.* TO 'ncdb'@'localhost';
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> exit;
Bye

OK root@ncloud:/var/www/nextcloud# sudo -u www-data php occ  maintenance:install --database "mysql" --database-name "nextcloud" --database-user "ncdb" --database-pass "dbpass" --database-host "localhost" --admin-user "admin" --admin-pass "adminpass"
MySQL username and/or password not valid
 -> You need to enter details of an existing account.
Trace: #0 /var/www/nextcloud/lib/private/Setup.php(354): OC\Setup\MySQL->setupDatabase()
#1 /var/www/nextcloud/core/Command/Maintenance/Install.php(108): OC\Setup->install()
#2 /var/www/nextcloud/3rdparty/symfony/console/Command/Command.php(255): OC\Core\Command\Maintenance\Install->execute()
#3 /var/www/nextcloud/3rdparty/symfony/console/Application.php(1009): Symfony\Component\Console\Command\Command->run()
#4 /var/www/nextcloud/3rdparty/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand()
#5 /var/www/nextcloud/3rdparty/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun()
#6 /var/www/nextcloud/lib/private/Console/Application.php(211): Symfony\Component\Console\Application->run()
#7 /var/www/nextcloud/console.php(100): OC\Console\Application->run()
#8 /var/www/nextcloud/occ(11): require_once('/var/www/nextcl...')
#9 {main}

Previous: Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [1045] Access denied for user 'ncdb'@'localhost' (using password: YES)
Trace: #0 /var/www/nextcloud/lib/private/Setup/MySQL.php(64): OC\DB\Connection->connect()
#1 /var/www/nextcloud/lib/private/Setup.php(354): OC\Setup\MySQL->setupDatabase()
#2 /var/www/nextcloud/core/Command/Maintenance/Install.php(108): OC\Setup->install()
#3 /var/www/nextcloud/3rdparty/symfony/console/Command/Command.php(255): OC\Core\Command\Maintenance\Install->execute()
#4 /var/www/nextcloud/3rdparty/symfony/console/Application.php(1009): Symfony\Component\Console\Command\Command->run()
#5 /var/www/nextcloud/3rdparty/symfony/console/Application.php(273): Symfony\Component\Console\Application->doRunCommand()
#6 /var/www/nextcloud/3rdparty/symfony/console/Application.php(149): Symfony\Component\Console\Application->doRun()
#7 /var/www/nextcloud/lib/private/Console/Application.php(211): Symfony\Component\Console\Application->run()
#8 /var/www/nextcloud/console.php(100): OC\Console\Application->run()
#9 /var/www/nextcloud/occ(11): require_once('/var/www/nextcl...')
#10 {main}

But I can login as ncdb using password…


 mysql -u ncdb -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 115
Server version: 10.3.36-MariaDB-0+deb10u2-log Raspbian 10

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> quit
Bye

as long you have console access you can reset passwords and 2FA of the user using occ

are you running this command from the old installation folder? could it happen old config file with old credentials still exists?

Hi,
I removed all relevant parts from the config.php:

sudoedit /var/www/nextcloud/config/config.php

Remove instanceid, passwordsalt, secret, dbtableprefix and installed config keys.

sudo touch /var/www/nextcloud/CAN_INSTALL

When I enter the password via the GUI, the db password I enter will be automatically be written to the config.php in a encrypted way. My old config.php had the password stored in cleartext.

edit: I just downloaded the latest nextcloud and unpacked it. I will try the same fing with less configurations in config.php

I would recommend you start with clean installation and add your old configurations one by one after successful basic setup…

I managed to install it. I twas indeed related to the config.php.
I started to move configs step by step. Works now!

1 Like