Nextcloud Pi where to find/put database

Support intro

Sorry to hear you’re facing problems. :slightly_frowning_face:

The community help forum (help.nextcloud.com) is for home and non-enterprise users. Support is provided by other community members on a best effort / “as available” basis. All of those responding are volunteering their time to help you.

If you’re using Nextcloud in a business/critical setting, paid and SLA-based support services can be accessed via portal.nextcloud.com where Nextcloud engineers can help ensure your business keeps running smoothly.

Getting help

In order to help you as efficiently (and quickly!) as possible, please fill in as much of the below requested information as you can.

Before clicking submit: Please check if your query is already addressed via the following resources:

(Utilizing these existing resources is typically faster. It also helps reduce the load on our generous volunteers while elevating the signal to noise ratio of the forums otherwise arising from the same queries being posted repeatedly).

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:

The Basics

  • Nextcloud Server version (e.g., 29.x.x):
    • Nextcloud Pi 1.55.3
  • Operating system and version (e.g., Ubuntu 24.04):
    • Debian (?)
  • Web server and version (e.g, Apache 2.4.25):
    • Apache2
  • PHP version (e.g, 8.3):
    • 8.1
  • Is this the first time you’ve seen this error? (Yes / No):
    • yes?
  • When did this problem seem to first start?
    • after exchange of usb drive

Summary of the issue you are facing:

My external drive had an error. I managed to extract the data dir and the database. Now I got a new drive and want to enable all of it again. Unfortunately it does not accept when I try to set the database directory.

Log entries

“Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [2002] No such file or directory”

Nextcloud

Please provide the log entries from your Nextcloud log that are generated during the time of problem (via the Copy raw option from Administration settings->Logging screen or from your nextcloud.log located in your data directory). Feel free to use a pastebin/gist service if necessary.

PASTE HERE

Configuration

Nextcloud

The output of occ config:list system or similar is best, but, if not possible, the contents of your config.php file from /path/to/nextcloud is fine (make sure to remove any identifiable information!):

occ: command not found

we need the content from the config.php

  • so the occ was executed without “:” i hope
  • in the directory where you executed occ is a file named this?
  • did you execute the occ in php context also like this
    sudo -u www-data php /path/to/nextcloud/occ

Basically, what exactly did you do?

You had all your data on an external hard drive?

Now you want to use a new hard drive, did you simply copy everything, did you install Nextcloud, and now you want to restore a backup, so to speak, and so on.

No, I executed the occ command in the /media/USBdrive

I had all the data on the hard drive already. I changed the database to also be on the hard drive and then switched the hard drive and copied everything over.

The install is still the same. I also have a backup some days before the problem arose, which I tried to apply. This resulted in the same error.

Using the command in the correct way produces

OCC

Cannot load Zend OPcache - it was already loaded
An unhandled exception has been thrown:
Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurre d in the driver: SQLSTATE[HY000] [2002] No such file or directory in /var/www/ne xtcloud/lib/private/DB/Connection.php:150
Stack trace:
#0 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1654): OC\DB\Con nection->connect()
#1 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1081): Doctrine\ DBAL\Connection->getWrappedConnection()
#2 /var/www/nextcloud/lib/private/DB/Connection.php(271): Doctrine\DBAL\Connecti on->executeQuery()
#3 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(341): OC \DB\Connection->executeQuery()
#4 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(377): Do ctrine\DBAL\Query\QueryBuilder->executeQuery()
#5 /var/www/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(280): Doctrin e\DBAL\Query\QueryBuilder->execute()
#6 /var/www/nextcloud/lib/private/AppConfig.php(440): OC\DB\QueryBuilder\QueryBu ilder->execute()
#7 /var/www/nextcloud/lib/private/AppConfig.php(206): OC\AppConfig->loadConfigVa lues()
#8 /var/www/nextcloud/lib/private/AppConfig.php(396): OC\AppConfig->getApps()
#9 /var/www/nextcloud/lib/private/App/AppManager.php(128): OC\AppConfig->getValu es()
#10 /var/www/nextcloud/lib/private/App/AppManager.php(149): OC\App\AppManager->g etInstalledAppsValues()
#11 /var/www/nextcloud/lib/private/legacy/OC_App.php(231): OC\App\AppManager->ge tInstalledApps()
#12 /var/www/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php(90): O C_App::getEnabledApps()
#13 /var/www/nextcloud/lib/base.php(700): OC\AppFramework\Bootstrap\Coordinator- >runInitialRegistration()
#14 /var/www/nextcloud/lib/base.php(1200): OC::init()
#15 /var/www/nextcloud/console.php(48): require_once(‘…’)
#16 /var/www/nextcloud/occ(11): require_once(‘…’)

Config
<?php
$CONFIG = array (
  'passwordsalt' => '',
  'secret' => '',
  'trusted_domains' => 
  array (
    0 => 'localhost',
    7 => '',
    5 => '',
    8 => '',
    3 => '',
    11 => '',
    1 => '',
    14 => '',
    20 => '',
  ),
  'datadirectory' => '/media/myCloudDrive/ncdata/data',
  'dbtype' => 'mysql',
  'version' => '28.0.14.1',
  'overwrite.cli.url' => 'https://nextcloud/',
  'dbname' => 'nextcloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => '',
  'dbpassword' => '',
  'installed' => true,
  'instanceid' => '',
  'memcache.local' => '\\OC\\Memcache\\Redis',
  'memcache.locking' => '\\OC\\Memcache\\Redis',
  'redis' => 
  array (
    'host' => '/var/run/redis/redis.sock',
    'port' => 0,
    'timeout' => 0.0,
    'password' => '',
  ),
  'tempdirectory' => '/media/myCloudDrive/ncdata/data/tmp',
  'mail_smtpmode' => 'smtp',
  'mail_smtpauthtype' => 'LOGIN',
  'mail_from_address' => '',
  'mail_domain' => '',
  'preview_max_x' => '2048',
  'preview_max_y' => '2048',
  'jpeg_quality' => '60',
  'overwriteprotocol' => 'https',
  'maintenance' => true,
  'logfile' => '/media/myCloudDrive/ncdata/data/nextcloud.log',
  'trusted_proxies' => 
  array (
    11 => '127.0.0.1',
    12 => '::1',
    14 => '',
  ),
  'loglevel' => '2',
  'log_type' => 'file',
  'mail_sendmailmode' => 'smtp',
  'mail_smtphost' => '',
  'mail_smtpport' => '',
  'mail_smtpauth' => 1,
  'mail_smtpname' => '',
  'mail_smtppassword' => '',
  'mail_smtpsecure' => '',
  'theme' => '',
);

So Nextcloud was installed on the broken hard drive? And only there?
Now you have the data on a new hard drive?

Based on the messages, you can tell that Nextcloud isn’t “installed.”

If you have all your data, you can perform a restore.

Restoring backup — Nextcloud latest Administration Manual latest documentation

No, Nextcloud is installed on the internal SD-Card of the Pi. Only the data was on the external drive.

The SD-Card works without a hitch. Analysing the error massage tells me that it tries to open a DB connection but fails due to not finding it.

My guess is, that when I exported the database I did something wrong and Nextcloud moved it instead. So now I want to move it back or tell nextcloud where to look for it.

But when I try to tell Nextcloud where to look for it, it tries to write the information into the database and throws the error. So my best bet for now is to move it, where it was originally stored so Nextcloud can find it again

Have you tried the restore as described in my post?

I still don’t quite understand what that has to do with the database if the data on the external hard drive was lost. If I understand correctly, you have NC on the SD card and the database is also stored there.

The occ command should also return a different response than “command not found” with an installed NC version – even if the database doesn’t exist or is incorrectly configured.

The occ command had different results as shown two answers above.

I think when I saved all my data I incidentally moved the database instead of copying it. So now I cannot find it on the SD-card anymore.

I have a folder ncdatabase containing nextcloud and mysql along other stuff in my local copy. I think that I just need to place these folders at the right place on the SD-card to get it working again.

Trying your link results into

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)

which also indicates that the database (server) was moved away. As host I used localhost as indicated in my config.php

You know how about a database is working?

Explain your remark. I dont know how Nextcloud handles the database or database connection.

As far as I can see the DB is hosted on a localhost MySql Server which should have database schemas for Nextcloud. If this is wrong feel free to correct it and tell me how to fix it.

I understand that you just want to copy the database file somewhere and then think it will work?

You have to import a file into the database simply copying the .sql file isn’t enough.

I also don’t know what the current problem is.

OCC works, yes/no?

Database is up-to-date, yes/no?

The last message is that MySQL isn’t running at all.

Sorry, I honestly don’t understand it anymore.

Yes, I want to copy the whole database somewhere. I hope that it will work then or that I can use native Nextcloud import of a backup to get the database in a state where I can use Nextcloud again.

I dont want to simply copy a .sql - I want to copy the whole database
I have a folder ncdatabase created by Nextcloud with these folders.

I can execute OCC and get this error

OCC

Cannot load Zend OPcache - it was already loaded An unhandled exception has been thrown: Doctrine\DBAL\Exception: Failed to connect to the database: An exception occurre d in the driver: SQLSTATE[HY000] [2002] No such file or directory in /var/www/ne xtcloud/lib/private/DB/Connection.php:150 Stack trace: #0 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1654): OC\DB\Con nection->connect() #1 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Connection.php(1081): Doctrine\ DBAL\Connection->getWrappedConnection() #2 /var/www/nextcloud/lib/private/DB/Connection.php(271): Doctrine\DBAL\Connecti on->executeQuery() #3 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(341): OC \DB\Connection->executeQuery() #4 /var/www/nextcloud/3rdparty/doctrine/dbal/src/Query/QueryBuilder.php(377): Do ctrine\DBAL\Query\QueryBuilder->executeQuery() #5 /var/www/nextcloud/lib/private/DB/QueryBuilder/QueryBuilder.php(280): Doctrin e\DBAL\Query\QueryBuilder->execute() #6 /var/www/nextcloud/lib/private/AppConfig.php(440): OC\DB\QueryBuilder\QueryBu ilder->execute() #7 /var/www/nextcloud/lib/private/AppConfig.php(206): OC\AppConfig->loadConfigVa lues() #8 /var/www/nextcloud/lib/private/AppConfig.php(396): OC\AppConfig->getApps() #9 /var/www/nextcloud/lib/private/App/AppManager.php(128): OC\AppConfig->getValu es() #10 /var/www/nextcloud/lib/private/App/AppManager.php(149): OC\App\AppManager->g etInstalledAppsValues() #11 /var/www/nextcloud/lib/private/legacy/OC_App.php(231): OC\App\AppManager->ge tInstalledApps() #12 /var/www/nextcloud/lib/private/AppFramework/Bootstrap/Coordinator.php(90): O C_App::getEnabledApps() #13 /var/www/nextcloud/lib/base.php(700): OC\AppFramework\Bootstrap\Coordinator- >runInitialRegistration() #14 /var/www/nextcloud/lib/base.php(1200): OC::init() #15 /var/www/nextcloud/console.php(48): require_once(‘…’) #16 /var/www/nextcloud/occ(11): require_once(‘…’)

Since I dont know where to look for the database, say a place where it should be, I cannot say anything about the state of the database. That is why I wrote that I think I moved it with the nextcloud command instead of copying it.

I am also fine with setting the database up again and importing the backup. But it seems that the whole database server is missing and I did not find a way to get that up and running again

ok step by step

First

systemctl status mysql

is the service installed or what is the status

if it is active/ running then check the ports

netstat -tuln | grep 3306 

The SQL backup must be on the server where the database is running, the path is secondary

 mariadb.service - MariaDB 10.5.28 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─ncp-delay-automount.conf
     Active: activating (start-pre) since Fri 2025-03-28 19:46:29 CET; 6s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 3002095 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
    Process: 3002096 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 3002098 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSI>
Cntrl PID: 3002196 (sleep)
      Tasks: 1 (limit: 57786)
        CPU: 229ms
     CGroup: /system.slice/mariadb.service
             └─3002196 /bin/sleep 20

netstat -tuln | grep 3306 

has no results.

And if you restart it?

Trying to restart

Job for mariadb.service failed because the control process exited with error code.
See "systemctl status mariadb.service" and "journalctl -xe" for details.

systemctl status mariadb.service

     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─ncp-delay-automount.conf
     Active: activating (start-pre) since Fri 2025-03-28 20:07:37 CET; 8s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 3009743 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
    Process: 3009744 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 3009746 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited>
Cntrl PID: 3009844 (sleep)
      Tasks: 1 (limit: 57786)
        CPU: 303ms
     CGroup: /system.slice/mariadb.service
             └─3009844 /bin/sleep 20
Mar 28 20:07:37 nextcloud systemd[1]: Starting MariaDB 10.5.28 database server...

journalctl


░░ The job identifier is 2185539 and the job result is done.
Mar 28 20:09:20 nextcloud systemd[1]: Starting MariaDB 10.5.28 database server...
░░ Subject: A start job for unit mariadb.service has begun execution
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░
░░ A start job for unit mariadb.service has begun execution.
░░
░░ The job identifier is 2185539.
Mar 28 20:09:22 nextcloud sudo[3010577]:     root : PWD=/ ; USER=www-data ; COMMAND=/usr/bin/php /var/www/nextcloud/occ config:system:get overwrite.cli.url
Mar 28 20:09:22 nextcloud sudo[3010577]: pam_unix(sudo:session): session opened for user www-data(uid=33) by (uid=0)
Mar 28 20:09:22 nextcloud bash[3010578]: Cannot load Zend OPcache - it was already loaded
Mar 28 20:09:22 nextcloud sudo[3010577]: pam_unix(sudo:session): session closed for user www-data
Mar 28 20:09:26 nextcloud sudo[3010581]:     root : PWD=/ ; USER=www-data ; COMMAND=/usr/bin/php /var/www/nextcloud/occ config:system:get overwrite.cli.url
Mar 28 20:09:26 nextcloud sudo[3010581]: pam_unix(sudo:session): session opened for user www-data(uid=33) by (uid=0)
Mar 28 20:09:26 nextcloud bash[3010582]: Cannot load Zend OPcache - it was already loaded
Mar 28 20:09:26 nextcloud sudo[3010581]: pam_unix(sudo:session): session closed for user www-data
Mar 28 20:09:28 nextcloud sudo[3010584]:  foundry : TTY=pts/0 ; PWD=/home/foundry ; USER=root ; COMMAND=/usr/bin/journalctl -xe
Mar 28 20:09:28 nextcloud sudo[3010584]: pam_unix(sudo:session): session opened for user root(uid=0) by foundry(uid=1002)
Mar 28 20:09:29 nextcloud sudo[3010587]:     root : PWD=/ ; USER=www-data ; COMMAND=/usr/bin/php /var/www/nextcloud/occ config:system:get overwrite.cli.url
Mar 28 20:09:29 nextcloud sudo[3010587]: pam_unix(sudo:session): session opened for user www-data(uid=33) by (uid=0)
Mar 28 20:09:29 nextcloud bash[3010588]: Cannot load Zend OPcache - it was already loaded

Status after restarting

 mariadb.service - MariaDB 10.5.28 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor prese>
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─ncp-delay-automount.conf
     Active: activating (auto-restart) (Result: exit-code) since Fri 2025-03-28>
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 3008576 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d />
    Process: 3008577 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP>
    Process: 3008579 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] >
    Process: 3008677 ExecStartPre=/bin/sleep 20 (code=exited, status=0/SUCCESS)
    Process: 3008762 ExecStart=/usr/sbin/mariadbd $MYSQLD_OPTS $_WSREP_NEW_CLUS>
   Main PID: 3008762 (code=exited, status=1/FAILURE)
     Status: "MariaDB server is down"
        CPU: 477ms

Ok you have to fix it.
you will find some on the internet about this “error”
You need a running instance, maybe you don’t need a database import and this is the root cause.