Database error after docker update: An exception occurred in the driver: SQLSTATE[HY000] [2002] (trying to connect via (null))

Nextcloud version (eg, 20.0.5): 25.0.5
Operating system and version (eg, Ubuntu 20.04): no idea, whatever the docker comes with
Apache or nginx version (eg, Apache 2.4.25): rno idea, whatever the docker comes with
PHP version (eg, 7.4): no idea, whatever the docker comes with

The issue you are facing:

Is this the first time you’ve seen this error? (Y/N): Y

Steps to replicate it:

  1. Have a running instance with v 25.0.4 in docker. MySQL DB is on separate server with SSL enabled (using a CA certificate).
  2. Update the docker to v25.0.5
  3. Run OCC in the docker

The output of your Nextcloud log in Admin > Logging:

N/A because not accessible

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

$CONFIG = array (
  'htaccess.RewriteBase' => '/',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'apps_paths' => 
  array (
    0 => 
    array (
      'path' => '/var/www/html/apps',
      'url' => '/apps',
      'writable' => false,
    1 => 
    array (
      'path' => '/var/www/html/custom_apps',
      'url' => '/custom_apps',
      'writable' => true,
  'instanceid' => 'oc9w5i6c5wr8',
  'passwordsalt' => '[REDACTED]',
  'secret' => '[REDACTED]',
  'trusted_domains' => 
  array (
    0 => '',
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'mysql',
  'version' => '',
  'overwrite.cli.url' => '[REDACTED]',
  'overwriteprotocol' => 'https',
  'dbname' => 'nextcloud',
  'dbhost' => '[REDACTED]',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => '[REDACTED]',
  'dbdriveroptions' => 
  array (
  'installed' => true,
  'memcache.distributed' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '[REDACTED]',
    'password' => '[REDACTED]',
    'dbindex' => 1,
    'port' => 6379,
  'data-fingerprint' => '[REDACTED]',
  'trusted_proxies' => 
  array (
    0 => '[REDACTED]',
  'maintenance' => false,
  'loglevel' => 1,
  'app_install_overwrite' => 
  array (
    0 => 'files_trackdownloads',
    1 => 'dicomviewer',
  'theme' => '',

The output of your Apache/nginx/system log in /var/log/____:

These don't seem to exist in the container.

Output errors in nextcloud.log in /var/www/ or as admin user in top right menu, filtering for errors. Use a pastebin service if necessary.

Doesn't seem to exist in the container either


I updated my docker image (using docker compose) from 25.0.4 to 25.0.5 and after that Nextcloud can’t connect to my database again (remote MySQL database with CA certificate access).

Trying to access my nextcloud instance through it’s url just gives me a sparse 500 page. Running occ gets me the following error:

An unhandled exception has been thrown:
Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002]  (trying to connect via (null)) in /var/www/html/lib/private/DB/Connection.php:139
Stack trace:
#0 /var/www/html/3rdparty/doctrine/dbal/src/Connection.php(1519): OC\DB\Connection->connect()
#1 /var/www/html/3rdparty/doctrine/dbal/src/Connection.php(1041): Doctrine\DBAL\Connection->getWrappedConnection()
#2 /var/www/html/lib/private/DB/Connection.php(261): Doctrine\DBAL\Connection->executeQuery('SELECT * FROM `...', Array, Array, NULL)
#3 /var/www/html/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(345): OC\DB\Connection->executeQuery('SELECT * FROM `...', Array, Array)
#4 /var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php(281): Doctrine\DBAL\Query\QueryBuilder->execute()
#5 /var/www/html/lib/private/AppConfig.php(419): OC\DB\QueryBuilder\QueryBuilder->execute()
#6 /var/www/html/lib/private/AppConfig.php(184): OC\AppConfig->loadConfigValues()
#7 /var/www/html/lib/private/AppConfig.php(375): OC\AppConfig->getApps()
#8 /var/www/html/lib/private/legacy/OC_App.php(967): OC\AppConfig->getValues(false, 'installed_versi...')
#9 /var/www/html/lib/private/Server.php(725): OC_App::getAppVersions()
#10 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\Server->OC\{closure}(Object(OC\Server))
#11 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(Pimple\Container))
#12 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(129): Pimple\Container->offsetGet('OC\\Memcache\\Fac...')
#13 /var/www/html/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query('OC\\Memcache\\Fac...', false)
#14 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\ServerContainer->query('OC\\Memcache\\Fac...')
#15 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(184): OC\AppFramework\Utility\SimpleContainer->get('OC\\Memcache\\Fac...')
#16 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(OC\Server))
#17 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(118): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(Pimple\Container))
#18 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(129): Pimple\Container->offsetGet('OCP\\ICacheFacto...')
#19 /var/www/html/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query('OCP\\ICacheFacto...', false)
#20 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\ServerContainer->query('OCP\\ICacheFacto...')
#21 /var/www/html/lib/private/Server.php(1119): OC\AppFramework\Utility\SimpleContainer->get('OCP\\ICacheFacto...')
#22 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\Server->OC\{closure}(Object(OC\Server))
#23 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(Pimple\Container))
#24 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(129): Pimple\Container->offsetGet('OCP\\Lock\\ILocki...')
#25 /var/www/html/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query('OCP\\Lock\\ILocki...', false)
#26 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\ServerContainer->query('OCP\\Lock\\ILocki...')
#27 /var/www/html/lib/private/Server.php(2070): OC\AppFramework\Utility\SimpleContainer->get('OCP\\Lock\\ILocki...')
#28 /var/www/html/lib/private/Files/View.php(117): OC\Server->getLockingProvider()
#29 /var/www/html/lib/private/Server.php(462): OC\Files\View->__construct()
#30 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(162): OC\Server->OC\{closure}(Object(OC\Server))
#31 /var/www/html/3rdparty/pimple/pimple/src/Pimple/Container.php(122): OC\AppFramework\Utility\SimpleContainer->OC\AppFramework\Utility\{closure}(Object(Pimple\Container))
#32 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(129): Pimple\Container->offsetGet('OC\\Files\\Node\\H...')
#33 /var/www/html/lib/private/ServerContainer.php(136): OC\AppFramework\Utility\SimpleContainer->query('OC\\Files\\Node\\H...', false)
#34 /var/www/html/lib/private/AppFramework/Utility/SimpleContainer.php(57): OC\ServerContainer->query('OC\\Files\\Node\\H...')
#35 /var/www/html/lib/private/Server.php(1472): OC\AppFramework\Utility\SimpleContainer->get('OC\\Files\\Node\\H...')
#36 /var/www/html/lib/base.php(617): OC\Server->boot()
#37 /var/www/html/lib/base.php(1144): OC::init()
#38 /var/www/html/console.php(48): require_once('/var/www/html/l...')
#39 /var/www/html/occ(11): require_once('/var/www/html/c...')
#40 {main}

I have occ aliased in the docker host like this: alias occ='docker exec -u www-data kekcloud php /var/www/html/occ'. Where kekcloud is the name of the container. The container I pull in docker compose is nextcloud:stable.

I have googled to no avail but I can’t find anything that seems even vaguely related to my problem.

The core of the issue sounds like a failure to connect to SQL. Do your SQL server logs say anything about it?

I don’t have access to those. It’s a managed database from Linode. But everything was working fine before the upgrade. All I did was

docker compose pull
docker compose down
docker compose up -d

I can still browse the database with client software by the way. The issue in my eyes is that for some reason, the configuration files with the db connection data are not being mounted properly in the container.

And they have no mechanism for you to view logs? That’s not good.

So you have a SQL DB that on its face appears to be ok, and a server saying it can’t connect to it. Can you connect to it with the MySQL client on the Nextcloud server? Have you verified all your SQL settings in the config are correct and intact?

By the way, docker compose down is not needed. It’ll recreate the containers automatically just from the up command.

Not just on the face of it. I can connect to it using DBeaver and see all the data in there.

Nothing about the DB changed before the update or during. The only thing that changed was the docker image.

Should the config.php file be executable or not? Because it isn’t at the moment.

I don’t think so. Generally all of Nextcloud’s files should be www-data:www-data and mode 750 folders and 640 files.

I just found my nextcloud.log file and it doesn’t contain any logs since the update.

And requesting status.php also returns a 500 error, but no additional data.