Fix “Failed to Connect to Database” in ownCloud 10 with MySQL

The quickest way to isolate an ownCloud 10 “Failed to connect to database” error is to test the same MySQL account, database name, and host from the ownCloud server itself. If that login fails, fix MySQL availability, network access, credentials, or grants first. If it succeeds, check ownCloud’s config/config.php, PHP’s pdo_mysql extension, and whether PHP is using the intended socket or TCP connection.

This guide covers an existing ownCloud Server 10 installation using MySQL or MariaDB on Linux. Service names and package commands vary by operating system and install type. Back up the configuration and database before editing production settings. Never share the database password in an issue or paste it into a public shell transcript.

What does the error tell you?

The message is a symptom, not a diagnosis. Read the ownCloud log and the web server or PHP log at the time of failure. The underlying exception may identify a missing driver, refused connection, rejected login, or unknown database. ownCloud’s Linux database guide requires PHP’s pdo_mysql extension and notes that the socket setting matters when MySQL is local. It recommends testing access with the MySQL command-line client.

Message or clueLikely area to check
could not find driver or a PDO driver errorThe web PHP runtime does not have pdo_mysql enabled.
SQLSTATE[HY000] [2002] or “Can’t connect”MySQL is stopped, the host or port is wrong, a firewall blocks TCP, or the socket path is wrong.
Access denied for userPassword, account host, or MySQL authentication settings do not match.
Unknown databaseThe configured database name is misspelled, missing, or not visible to the account.

Exact error codes can vary by PHP, MySQL, MariaDB, and operating-system versions. Treat them as clues and confirm the cause with the checks below. MySQL’s access-denied documentation notes that account and host matching are common causes.

Can the ownCloud host reach MySQL?

Find out whether MySQL runs on the ownCloud server, another machine, or a container. On Linux, check the service. Common unit names are mysql and mariadb; use the one installed on your server:

sudo systemctl status mysql
sudo systemctl status mariadb

If it is inactive, inspect the journal or database error log before restarting it. A configuration error, full disk, failed database recovery, or port conflict may prevent startup:

sudo journalctl -u mariadb --since "30 minutes ago"
sudo systemctl start mariadb

Replace the service name as appropriate. A running service does not prove that ownCloud can authenticate; continue with the account test.

For a remote database, test DNS and the configured TCP port from the ownCloud host. MySQL commonly listens on port 3306, although deployments may use another port:

getent hosts db.example.net
nc -vz db.example.net 3306

A failed check points toward DNS, routing, a firewall, or a database listener configuration. Allow connections only from the ownCloud server over a private network where possible. Do not expose MySQL to the public internet as a shortcut.

Does the database account work from the ownCloud host?

Run the MySQL client on the application server with the same database name, user, and destination host that ownCloud should use. The -p option prompts privately; it avoids putting the password in the command itself:

mysql -u oc_app -p -h localhost owncloud

For a remote database, replace localhost with its hostname. If login works, run a harmless verification:

SELECT DATABASE(), CURRENT_USER();
SHOW TABLES;
EXIT;

This confirms basic authentication and access to the selected database. If it fails, read the exact error and the username/host MySQL reports. MySQL treats username and host together when matching an account. Also note that localhost on Linux commonly uses a Unix socket, while 127.0.0.1 forces TCP. Test the same connection method your ownCloud configuration uses:

mysql -u oc_app -p -h 127.0.0.1 owncloud

Are the ownCloud database settings correct?

Inspect the active config/config.php in the ownCloud installation directory. The ownCloud configuration reference lists database type, name, user, and password settings; its database guide also shows the host and table prefix. A typical MySQL configuration resembles:

'dbtype' => 'mysql',
'dbname' => 'owncloud',
'dbuser' => 'oc_app',
'dbpassword' => 'REDACTED',
'dbhost' => 'localhost',
'dbtableprefix' => 'oc_',

Check for spelling mistakes, accidental whitespace, a stale password, a database name with different capitalization, or a host pointing at the wrong server. Preserve the rest of the file, including the instance secret and data directory. Do not replace the entire configuration with this example.

After an edit, confirm the file is valid PHP using the PHP binary for your installation:

php -l /var/www/owncloud/config/config.php

Your installation path may differ. Restrict access to config.php; it contains database credentials and other sensitive values.

Is PHP’s MySQL driver enabled for the web application?

ownCloud 10’s database guide requires pdo_mysql. Check PHP’s version and loaded modules:

php -v
php -m | grep -i pdo_mysql

If the module is missing, install the corresponding MySQL PDO package for your PHP version, then restart or reload the relevant web server or PHP-FPM pool. Package names differ across Ubuntu, Debian, SUSE, Red Hat, and container images. A module enabled for command-line PHP may not be enabled for Apache or PHP-FPM, so verify the web runtime’s PHP configuration too. Avoid leaving a public diagnostic page that reveals PHP configuration information.

Could the socket or host setting be wrong?

On Linux, a MySQL client may use a Unix socket for localhost, while 127.0.0.1 uses TCP. If MySQL is on the same machine, check whether PHP’s mysql.default_socket points to the socket file that the database server actually creates. Compare the database server’s socket and port settings with PHP’s settings and ownCloud’s host value.

If MySQL is remote, localhost is the ownCloud machine, not the database server. Set the reachable database hostname instead, and make sure MySQL listens on the intended interface. A firewall or a local-only bind-address can prevent remote access even when local database commands work. Restrict access to the application server’s private address.

Do the MySQL account and grants match the client host?

MySQL accounts include a username and a host component. Therefore, 'oc_app'@'localhost' and 'oc_app'@'10.0.0.25' are different account entries. Use an administrative connection to inspect available accounts and the grants for the account that should match:

SELECT User, Host FROM mysql.user;
SHOW GRANTS FOR 'oc_app'@'localhost';

If the account is missing and the database already exists, create a dedicated account and grant it privileges only on the ownCloud database. Replace the sample database, host, and password with your actual values:

CREATE USER 'oc_app'@'localhost' IDENTIFIED BY 'replace-with-a-strong-password';
GRANT ALL PRIVILEGES ON owncloud.* TO 'oc_app'@'localhost';

For a remote database, use the application server’s actual host in the account definition. Avoid a wildcard host or global privileges as a quick fix, and do not run ownCloud as MySQL root. If the account already exists, review its grant and reset the password deliberately rather than creating duplicate accounts. Retest the login from the ownCloud server.

How do you confirm the repair?

After changing one item at a time, confirm that the same MySQL command-line login works from the ownCloud host, the web PHP runtime has pdo_mysql, and the ownCloud log no longer records a connection exception. Reload the site and perform a basic read and write operation only after the instance is available again.

If the command-line login succeeds but ownCloud still fails, compare the exact host form, account, database name, and PHP runtime used by the web process with the working test. Check the web server or PHP-FPM logs at the time of the request. For an already installed server, repair its existing configuration carefully; do not delete the database or rerun installation as a troubleshooting shortcut.

For further reference, read the ownCloud Server 10.16 database configuration and troubleshooting guide, the ownCloud 10.15 configuration reference, and MySQL’s official guides to connection troubleshooting and access-denied errors. Service names, package commands, and exact settings depend on your operating system and deployment.

Leave a Comment

7 Best WSUS Tools for Update Management and Troubleshooting

7 Best WSUS Tools for Update Management and Troubleshooting

Compare seven tools that support or complement WSUS, from Microsoft’s native console and diagnostics to third-party patch publishing and remote deployment.

Best Windows System Monitoring Tools: 6 Picks for Server Visibility

Best Windows System Monitoring Tools: 6 Picks for Server Visibility

Compare six Windows system monitoring tools for server health, application visibility, and alerting, with current notes on deployment and licensing.

7 Wake-on-LAN Tools: What’s Still Available From the 2021 List

7 Wake-on-LAN Tools: What’s Still Available From the 2021 List

Compare seven Wake-on-LAN tools by features and availability, including free utilities, network-admin suites, and 2021 picks that have since been retired.

9 Best Ping Tools for Testing Latency and Scanning a Network

9 Best Ping Tools for Testing Latency and Scanning a Network

Compare nine ping tools for quick reachability checks, subnet discovery, TCP tests, and latency monitoring, with guidance on which one fits your network task.

Best TFTP Servers for Windows, Linux, and macOS

Best TFTP Servers for Windows, Linux, and macOS

Compare the best TFTP servers for Windows, Linux, and macOS, including SolarWinds, Tftpd64, tftpd-hpa, atftpd, haneWIN, and dnsmasq.

5 Best Microsoft Access Alternatives for Desktop and Web Databases

5 Best Microsoft Access Alternatives for Desktop and Web Databases

Compare five Microsoft Access alternatives for desktop, SQLite, no-code, and browser-based database work, with strengths, limits, and best-fit use cases.

Open-Source vs. Closed-Source Monitoring Tools Compared

Open-Source vs. Closed-Source Monitoring Tools Compared

Compare open-source and closed-source monitoring tools by cost, support, customization, security, and current options including Zabbix, Nagios, PRTG, and more.

Ingress vs. Egress: What’s the Difference in Networking?

Ingress vs. Egress: What’s the Difference in Networking?

Understand how ingress and egress describe incoming and outgoing traffic, why direction depends on the network boundary, and how to monitor bandwidth and spot risky data transfers.

6 Best Free Syslog Servers to Try for Centralized Logging

6 Best Free Syslog Servers to Try for Centralized Logging

Compare six free syslog servers and collectors for Windows and Linux, including GUI tools, open-source options, search, alerting, and secure transport.

What Is IIS? Microsoft’s Windows Web Server and Alternatives

What Is IIS? Microsoft’s Windows Web Server and Alternatives

See what Microsoft IIS does, how its request pipeline and application pools work, and when Apache, NGINX, or Caddy may fit your web server needs better.