"Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000]

Nextcloud version (eg, 18.0.2): 19.02
Operating system and version (eg, Ubuntu 20.04): Ubuntu 20.04
Apache or nginx version (eg, Apache 2.4.25): Server version: Apache/2.4.41 (Ubuntu)
PHP version (eg, 7.1): PHP 7.4.3 (cli) (built: May 26 2020 12:24:22) ( NTS )

The issue you are facing:
I get a Internal Server Error
Is this the first time you’ve seen this error? (Y/N): Y

Steps to replicate it:

  1. Goto cloud.sturtz.ml

The output of your Nextcloud log in Admin > Logging:

{"reqId":"st659vFBTHLi3PTaPi0v","level":3,"time":"2020-09-22T19:48:51+00:00","remoteAddr":"2604:99c0:8:2f96:1454:6052:95de:d5bf","user":"--","app":"core","method":"GET","url":"/favicon.ico","message":{"Exception":"Doctrine\\DBAL\\DBALException","Message":"Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [2002] No such file or directory","Code":0,"Trace":[{"file":"/home/cloud/public_html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php","line":889,"function":"connect","class":"OC\\DB\\Connection","type":"->"},{"file":"/home/cloud/public_html/lib/private/DB/Connection.php","line":194,"function":"executeQuery","class":"Doctrine\\DBAL\\Connection","type":"->"},{"file":"/home/cloud/public_html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Query/QueryBuilder.php","line":200,"function":"executeQuery","class":"OC\\DB\\Connection","type":"->"},{"file":"/home/cloud/public_html/lib/private/DB/QueryBuilder/QueryBuilder.php","line":216,"function":"execute","class":"Doctrine\\DBAL\\Query\\QueryBuilder","type":"->"},{"file":"/home/cloud/public_html/lib/private/AppConfig.php","line":331,"function":"execute","class":"OC\\DB\\QueryBuilder\\QueryBuilder","type":"->"},{"file":"/home/cloud/public_html/lib/private/AppConfig.php","line":109,"function":"loadConfigValues","class":"OC\\AppConfig","type":"->"},{"file":"/home/cloud/public_html/lib/private/AppConfig.php","line":287,"function":"getApps","class":"OC\\AppConfig","type":"->"},{"file":"/home/cloud/public_html/lib/private/legacy/OC_App.php","line":883,"function":"getValues","class":"OC\\AppConfig","type":"->"},{"file":"/home/cloud/public_html/lib/private/TemplateLayout.php","line":164,"function":"getAppVersions","class":"OC_App","type":"::"},{"file":"/home/cloud/public_html/lib/private/legacy/OC_Template.php","line":185,"function":"__construct","class":"OC\\TemplateLayout","type":"->"},{"file":"/home/cloud/public_html/lib/private/Template/Base.php","line":132,"function":"fetchPage","class":"OC_Template","type":"->"},{"file":"/home/cloud/public_html/lib/private/legacy/OC_Template.php","line":334,"function":"printPage","class":"OC\\Template\\Base","type":"->"},{"file":"/home/cloud/public_html/index.php","line":63,"function":"printExceptionErrorPage","class":"OC_Template","type":"::"}],"File":"/home/cloud/public_html/lib/private/DB/Connection.php","Line":67,"CustomMessage":"--"},"userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36","version":"19.0.3.1"}


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

<?php
$CONFIG = array (
  'passwordsalt' => 'aYy+q9***I2wTMZ1472Pns',
  'secret' => 'HXY8PsyBAy55tvIuB3qMC3ZmsjqPRJ***G',
  'trusted_domains' => 
  array (
    0 => 'cloud.sturtz.ml',
  ),
  'datadirectory' => '/data',
  'htaccess.RewriteBase' => '/',
  'dbtype' => 'mysql',
  'version' => '19.0.3.1',
  'overwrite.cli.url' => 'https://cloud.sturtz.ml',
  'dbname' => '***',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'SC_',
  'mysql.utf8mb4' => true,
  'dbuser' => '***',
  'dbpassword' => '***',
  'installed' => true,
  'instanceid' => '***',
  'mail_smtpmode' => 'sendmail',
  'mail_sendmailmode' => 'smtp',
  'mail_from_address' => 'no.reply',
  'mail_domain' => 'sturtz.ml',
  'maintenance' => false,
  'ldapIgnoreNamingRules' => false,
  'ldapProviderFactory' => 'OCA\\User_LDAP\\LDAPProviderFactory',
  'user_sql.db.database' => '***',
  'user_sql.db.hostname' => 'localhost',
  'user_sql.db.password' => '***',
  'user_sql.db.username' => '***',
);

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


[Tue Sep 22 15:00:31.803121 2020] [mpm_prefork:notice] [pid 1523] AH00171: Graceful restart requested, doing restart
PHP Warning:  PHP Startup: Unable to load dynamic library 'mysql.so' (tried: /usr/lib/php/20190902/mysql.so (/usr/lib/php/20190902/mysql.so: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/mysql.so.so (/usr/lib/php/20190902/mysql.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning:  Module 'PDO' already loaded in Unknown on line 0
PHP Warning:  Module 'PDO' already loaded in Unknown on line 0
[Tue Sep 22 15:00:33.245566 2020] [mpm_prefork:notice] [pid 1523] AH00163: Apache/2.4.41 (Ubuntu) mod_fcgid/2.3.9 OpenSSL/1.1.1f configured -- resuming normal operations
[Tue Sep 22 15:00:33.245600 2020] [core:notice] [pid 1523] AH00094: Command line: '/usr/sbin/apache2'
wsd-12152-12152 2020-09-22 20:03:32.670693 [ loolwsd ] SIG   Shutdown signal received: SIGTERM
wsd-12152-12152 2020-09-22 20:03:32.831184 [ loolwsd ] SIG   Forced-Termination signal received: SIGTERM
[Tue Sep 22 15:03:33.815904 2020] [mpm_prefork:notice] [pid 1523] AH00169: caught SIGTERM, shutting down
[Tue Sep 22 15:07:39.150121 2020] [suexec:notice] [pid 1257] AH01232: suEXEC mechanism enabled (wrapper: /usr/lib/apache2/suexec)
PHP Warning:  PHP Startup: Unable to load dynamic library 'mysql.so' (tried: /usr/lib/php/20190902/mysql.so (/usr/lib/php/20190902/mysql.so: cannot open shared object file: No such file or directory), /usr/lib/php/20190902/mysql.so.so (/usr/lib/php/20190902/mysql.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
PHP Warning:  Module 'PDO' already loaded in Unknown on line 0
PHP Warning:  Module 'PDO' already loaded in Unknown on line 0
[Tue Sep 22 15:07:45.652961 2020] [mpm_prefork:notice] [pid 1518] AH00163: Apache/2.4.41 (Ubuntu) mod_fcgid/2.3.9 OpenSSL/1.1.1f configured -- resuming normal operations
[Tue Sep 22 15:07:45.653016 2020] [core:notice] [pid 1518] AH00094: Command line: '/usr/sbin/apache2'
[Tue Sep 22 15:08:36.379407 2020] [fcgid:warn] [pid 1520] mod_fcgid: process 1745 graceful kill fail, sending SIGKILL
sh: 1: disown: not found
Security: Check for the 'lool' username overridden on the command line.
Init vcl
preload: merged unordf ucpchelp1 msforms vbaobj pcr vbaswobj sw animcore hwp flash chartcore solver sc wpftcalc xof ucpcmis1 wpftdraw sd svgfilter evtatt graphicfilter wpftimpress sdfilt sm pdffilter PresentationMinimizer protocolhandler ucpdav1 wpftwriter msword writerfilter t602filter xmlfa basctl binaryurp uuresolver scd chartcontroller ldapbe2 dba sdbt deploymentgui migrationoo2 migrationoo3 xsltfilter sdd embobj emboleobj log expwrap odfflatxml textfd storagefd xmlfd frm fwl fwm io textconversiondlgs smd mozbootstrap oox scfilt slideshow proxyfac vclcanvas canvasfactory mtfrenderer simplecanvas dlgprov basprov stringresource dbaxml calc dbase flat writer reflection bootstrap introspection invocation invocadapt namingservice stocservices cached1 ucppkg1 srtrs1 ucptdoc1 xsltdlg swd cui bib guesslang numbertext offacc scn scriptframe dbpool2 xmlsecurity analysis date pricing fps_office i18nsearch xsec_xmlsec emfio vbaevents pdfimport mysql_jdbc ucpext hyphen spell lnth for ctl passwordcontainer svgio
Absent (often optional): sm sm sm sm sm sm sm sm sm sm sm smd 
Disabled: ucpftp1 rptxml dbu dbmm rptui rpt mork odbc sdbc2 cmdmail syssh ucphier1 ucpimage PresenterScreen abp dbp updatefeed 
Whitelisted languages: de_DE en_GB en_US es_ES fr_FR it nl pt_BR pt_PT ru 
Preloading dictionaries: de_DE en_US fr_FR it_IT nl_NL pt_BR ru_RU en_GB it_CH nl_BE pt_PT es_ES 
Preloading thesauri: de_DE en_US fr_FR it_IT nl_NL pt_BR ru_RU en_GB it_CH nl_BE pt_PT es_ES 
Preload icons
Preload languages
Preload fonts
Ready to accept connections on port 9982.

You can access the full log
http://sturtznetwork.atwebpages.com/paste/nextcloud.log.paste

I am seeing something similar on NCP.

I fixed the issue now I am getting a diffrent log error

How did you fix it?

I just rebooted my server

My server is running super slow right now and webmin will not load so I cannot see what is going on

In mysql enter the command: ALTER USER ‘root’@‘localhost’ IDENTIFIED WITH mysql_native_password BY ‘newpassword’;