Database connection lost after reboot

Nextcloud version (eg, 12.0.2) : 15.0.2
Operating system and version (eg, Ubuntu 17.04) : Docker
Apache or nginx version (eg, Apache 2.4.25) : Apache 2
PHP version (eg, 7.1) : 7.2.14

The issue you are facing:

After restarting my nextcloud host device and after it came back up nextcloud no longer had any connection to the database. The database is up as i can access it via phpMyAdmin yet nextcloud cannot connect to it. I even rebuilt the database entirely as a docker image, it was running on the host OS before, to no avail

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

Steps to replicate it:

  1. have working nextcloud setup with external mysql database
  2. restart host computer

The output of your Nextcloud log in Admin > Logging:

[Thu Mar 07 17:04:32.939414 2019] [php7:error] [pid 34] [client 10.10.10.3:21620] PHP Fatal error:  Uncaught Doctrine\\DBAL\\DBALException: Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [2002] Connection timed out in /var/www/html/lib/private/DB/Connection.php:64\nStack trace:\n#0 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(429): OC\\DB\\Connection->connect()\n#1 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389): Doctrine\\DBAL\\Connection->getDatabasePlatformVersion()\n#2 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(328): Doctrine\\DBAL\\Connection->detectDatabasePlatform()\n#3 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(623): Doctrine\\DBAL\\Connection->getDatabasePlatform()\n#4 /var/www/html/lib/private/DB/Connection.php(151): Doctrine\\DBAL\\Connection->setTransactionIsolation(2)\n#5 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(172): OC\\DB\\Connection->__construct(Array, Object(Doctrine\\DBAL\\Driver\\PDOMySql\\Driver), Object(Doctrine\\DBAL\\Configuration), Object in /var/www/html/lib/private/DB/Connection.php on line 64,
[Thu Mar 07 17:04:33.483929 2019] [php7:error] [pid 36] [client 10.10.10.3:21621] PHP Fatal error:  Uncaught Doctrine\\DBAL\\DBALException: Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [2002] Connection timed out in /var/www/html/lib/private/DB/Connection.php:64\nStack trace:\n#0 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(429): OC\\DB\\Connection->connect()\n#1 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389): Doctrine\\DBAL\\Connection->getDatabasePlatformVersion()\n#2 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(328): Doctrine\\DBAL\\Connection->detectDatabasePlatform()\n#3 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(623): Doctrine\\DBAL\\Connection->getDatabasePlatform()\n#4 /var/www/html/lib/private/DB/Connection.php(151): Doctrine\\DBAL\\Connection->setTransactionIsolation(2)\n#5 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(172): OC\\DB\\Connection->__construct(Array, Object(Doctrine\\DBAL\\Driver\\PDOMySql\\Driver), Object(Doctrine\\DBAL\\Configuration), Object in /var/www/html/lib/private/DB/Connection.php on line 64,
10.10.10.3 - ***** [07/Mar/2019:17:02:33 +0000] "GET /ocs/v2.php/apps/notifications/api/v2/notifications?format=json HTTP/1.1" 500 211 "-" "Mozilla/5.0 (Windows) mirall/2.5.1final (build 20181204) (Nextcloud)",
[Thu Mar 07 17:04:34.887842 2019] [php7:error] [pid 87] [client 10.10.10.3:21570] PHP Fatal error:  Uncaught Doctrine\\DBAL\\DBALException: Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [2002] Connection timed out in /var/www/html/lib/private/DB/Connection.php:64\nStack trace:\n#0 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(429): OC\\DB\\Connection->connect()\n#1 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(389): Doctrine\\DBAL\\Connection->getDatabasePlatformVersion()\n#2 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(328): Doctrine\\DBAL\\Connection->detectDatabasePlatform()\n#3 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(623): Doctrine\\DBAL\\Connection->getDatabasePlatform()\n#4 /var/www/html/lib/private/DB/Connection.php(151): Doctrine\\DBAL\\Connection->setTransactionIsolation(2)\n#5 /var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/DriverManager.php(172): OC\\DB\\Connection->__construct(Array, Object(Doctrine\\DBAL\\Driver\\PDOMySql\\Driver), Object(Doctrine\\DBAL\\Configuration), Object in /var/www/html/lib/private/DB/Connection.php on line 64,
10.10.10.3 - ***** [07/Mar/2019:17:02:04 +0000] "GET /status.php HTTP/1.1" 500 0 "-" "Mozilla/5.0 (Windows) mirall/2.5.1final (build 20181204) (Nextcloud)"

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

<?php
$CONFIG = array (
  'htaccess.RewriteBase' => '/',
  'trusted_domains' =>
  array (
    0 => 'X.X.X.55:8080',
  ),
  'trusted proxies' =>
  array (
    0 => 'X.X.X.3',
  ),
  'mail_smtpdebug' => 'true',
  'overwritewebroot' => '/',
  'overwritehost' => '*****',
  'overwriteprotocol' => 'https',
  'overwritecondaddr' => '^X\\.X\\.X\\.3$',
  '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,
    ),
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'mysql',
  'version' => '15.0.2.0',
  'overwrite.cli.url' => 'http://X.X.X.55:8080',
  'installed' => true,
  'mysql.utf8mb4' => true,
  'maintenance' => false,
  'dbname' => 'nextcloud',
  'dbhost' => 'X.X.X.55:3306',
  'dbuser' => 'nextcloud',
  'dbpassword' => '*****',
  'ldapIgnoreNamingRules' => false,
  'ldapProviderFactory' => 'OCA\\User_LDAP\\LDAPProviderFactory',
  'mail_smtpmode' => 'smtp',
  'mail_sendmailmode' => '*****',
  'mail_from_address' => '*****',
  'mail_domain' => '*****',
  'mail_smtphost' => '*****',
  'mail_smtpport' => '25',
);

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

No web logs

As already discussed in other threads you should make sure that
a) your MySQL daabase is up-and-running.
b) the required PHP database module has correctly been installed.
c) the MySQL PHP database module is correctly activated in the php.ini file.
d) the MySQL PHP database module is correctly loaded.

You can check this by creating e.g. an info.php file which contains the following code <?php phpinfo() ?> and save it in your web server root. Once you’ve done this you should check which
modules are loaded by accessing the url http://<your-server-name-or-ip>/info.php.

the database is up and running as i can connect to and manioulate it with myPhpAdmin as well as with telnet.

I am unable to find a php.ini but i did find php.ini-production and php.ini-development

as far as I’m aware the php modules seem to be properly loaded as far as I can tell



I wont bother with uploading the mysqlnd statistics as they are all 0

I thank you for the quick reply and am sorry that I posted this thread a second time :frowning:

Ok, that you can access the database using PHPmyadmin sounds good. Nevertheless Nextcloud is still not able to access it.
Do you have any Firewall or port forwarding in between which could block access from the Nextcloud server to the database?
Is the database running on the same environment as Nextcloud?
If yes, it would be worse to try to access it using the loopback address. Before doing this you should make sure that the Nextcloud server is allowed to access the database by running the following command: > SELECT user,host FROM mysql.user;

I got it working!

I changed the db ip in the nextcloud config.php to the ip on the db docker container, which is inside the docker network and viola, connection restored.

Its weird that upon initial install the nextcloud worked perfectly but after a reboot it could’nt find the db anymore :confused:

Thanks again for all your help! :slight_smile:

1 Like