Need help with restoring mysql database after deletion

Support intro

Sorry to hear you’re facing problems :slightly_frowning_face:

help.nextcloud.com is for home/non-enterprise users. If you’re running a business, paid support can be accessed via portal.nextcloud.com where we can ensure your business keeps running smoothly.

In order to help you as quickly as possible, before clicking Create Topic please provide as much of the below as you can. Feel free to use a pastebin service for logs, otherwise either indent short log examples with four spaces:

example

Or for longer, use three backticks above and below the code snippet:

longer
example
here

Some or all of the below information will be requested if it isn’t supplied; for fastest response please provide as much as you can :heart:

Nextcloud version (eg, 29.0.5): 29.0.7.1
Operating system and version (eg, Ubuntu 24.04): Debian 12
Apache or nginx version (eg, Apache 2.4.25): replace me
PHP version (eg, 8.3): 8.2.20

The issue you are facing:
I accidentally deleted my DB, how could I restore it?

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

Steps to replicate it:

The output of your Nextcloud log in Admin > Logging:

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

<?php
$CONFIG = array (
  'instanceid' => 'Redacted',
  'passwordsalt' => 'Redacted',
  'secret' => 'Redacted',
  'trusted_domains' => 
  array (
    0 => 'Redacted',
  ),
  'datadirectory' => '/var/www/nextcloud/data',
  'dbtype' => 'mysql',
  'version' => '29.0.7.1',
  'overwrite.cli.url' => 'Redacted',
  'overwriteprotocol' => 'https',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost:8080',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextclouduser',
  'dbpassword' => 'Redacted',
  'installed' => true,
  'theme' => '',
  'loglevel' => 2,
  'maintenance' => false,
  'updater.release.channel' => 'stable',
);

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

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.

I spotted this in the error, and this is what happens when accessing the website 
```Internal Server Error

The server encountered an internal error and was unable to complete your request.
Please contact the server administrator if this error reappears multiple times, please include the technical details below in your report.
More details can be found in the server log.```
```Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [1045] Access denied for user 'nextclouduser'@'localhost' (using password: YES)```

If you have made no backups of your database, there is no way you can restore it.

There are several factors that might help you, if those factors are in favor for you:

If you use an LDAP, you have lost no users.

User data is not lost but please make a backup of all the data, preferably to another disk.

Anything else (Apps, settings, app passwords, calendars, contacts, flow rules, shares information - NOT the shares themselves though and basically everything else exclusively stored in the database) is gone.

You are best helped forward by installing a fresh nextcloud entirely. However save your config.php file as you will need everything inside it (database settings, known hosts, redis, etc.).

alright well I don’t care too much if I can atleast restore the apps and the files, anyway how could I restart the install from a fresh start?

Because you have no database you can do a fresh install with the newest Nextcloud version 30. After that create your user or users and delete the default files in Nextcloud GUI.

You can copy or move the files back in the correct directory trees e.g. /path/to/nextloud/data/username/files. After that you can use the following command that Nextcloud recognises the files:

sudo -u www-data /path/to/nextcloud/occ files:scan --all

documentation

If you use Group folders also create first the old empty Group folders.

2 Likes