# Database connection lost after reboot

**URL:** <https://help.nextcloud.com/t/database-connection-lost-after-reboot/50000>\
**Category:** 📦 Appliances (Docker, Snappy, VM, NCP, AIO)\
**Tags:** database\
**Created:** [March 21, 2019, 5:06pm UTC](https://help.nextcloud.com/t/database-connection-lost-after-reboot/50000 "2019-03-21T17:06:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![pizzaandcheese](https://help.nextcloud.com/letter_avatar/pizzaandcheese/32/6_22734026db12803ebb3e059622ac3534.png) [@pizzaandcheese](https://help.nextcloud.com/u/pizzaandcheese)\
**Post date:** [March 21, 2019, 5:06pm UTC](https://help.nextcloud.com/t/database-connection-lost-after-reboot/50000/1 "2019-03-21T17:06:26Z")

</div>

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** :

```auto
[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!):

```auto
<?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/ ____ `:

```auto
No web logs

```

---

<div class="post-metadata">

**Author:** ![j-ed](https://help.nextcloud.com/user_avatar/help.nextcloud.com/j-ed/32/7281_2.png) [@j-ed](https://help.nextcloud.com/u/j-ed)\
**Post date:** [March 21, 2019, 6:06pm UTC](https://help.nextcloud.com/t/database-connection-lost-after-reboot/50000/2 "2019-03-21T18:06:45Z")

</div>

> [@pizzaandcheese](#):
>
> Failed to connect to the database: An exception occured in driver: SQLSTATE[HY000] [2002]

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`.

---

<div class="post-metadata">

**Author:** ![pizzaandcheese](https://help.nextcloud.com/letter_avatar/pizzaandcheese/32/6_22734026db12803ebb3e059622ac3534.png) [@pizzaandcheese](https://help.nextcloud.com/u/pizzaandcheese)\
**Post date:** [March 21, 2019, 7:08pm UTC](https://help.nextcloud.com/t/database-connection-lost-after-reboot/50000/3 "2019-03-21T19:08:05Z")

</div>

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

 ![phpinfo_mysql_site](https://help.nextcloud.com/uploads/default/original/2X/a/a27a007e78715f3be1190671abb02086be41c90e.png)  
 ![mysql_phpinfo](https://help.nextcloud.com/uploads/default/original/2X/8/8e3645441fd3ad1501267c83997a28d5b993b3e5.png)  
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 ☹

---

<div class="post-metadata">

**Author:** ![j-ed](https://help.nextcloud.com/user_avatar/help.nextcloud.com/j-ed/32/7281_2.png) [@j-ed](https://help.nextcloud.com/u/j-ed)\
**Post date:** [March 22, 2019, 7:35am UTC](https://help.nextcloud.com/t/database-connection-lost-after-reboot/50000/4 "2019-03-22T07:35:32Z")

</div>

> [@pizzaandcheese](#):
>
> ‘dbtype’ =\> ‘mysql’,  
> ‘dbname’ =\> ‘nextcloud’,  
> ‘dbhost’ =\> ‘X.X.X.55:3306’,  
> ‘dbuser’ =\> ‘nextcloud’,  
> ‘dbpassword’ =\> ‘\*\*\*\*\*’,

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;`

---

<div class="post-metadata">

**Author:** ![pizzaandcheese](https://help.nextcloud.com/letter_avatar/pizzaandcheese/32/6_22734026db12803ebb3e059622ac3534.png) [@pizzaandcheese](https://help.nextcloud.com/u/pizzaandcheese)\
**Post date:** [March 22, 2019, 2:31pm UTC](https://help.nextcloud.com/t/database-connection-lost-after-reboot/50000/5 "2019-03-22T14:31:04Z")

</div>

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 😕

Thanks again for all your help! 🙂

---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [December 4, 2024, 9:35am UTC](https://help.nextcloud.com/t/database-connection-lost-after-reboot/50000/6 "2024-12-04T09:35:36Z")

</div>



---

<div class="post-metadata">

**Author:** ![wwe](https://help.nextcloud.com/user_avatar/help.nextcloud.com/wwe/32/72963_2.png) [@wwe](https://help.nextcloud.com/u/wwe)\
**Post date:** [December 11, 2024, 2:40pm UTC](https://help.nextcloud.com/t/database-connection-lost-after-reboot/50000/7 "2024-12-11T14:40:44Z")

</div>


