Question

Error: Database connection failed

Hi, I got this Error:

It is possible that the database is overloaded or otherwise not running properly.

The site administrator should also check that the database details have been correctly specified in config.php


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
May 28, 2025

Hey Ismail,

That message usually pops up when there’s a problem connecting to your database. It could be something as simple as a typo in your config.php, double-check the database name, username, password, and host just to be safe.

Another common issue is that the database server itself isn’t running properly. If you’re on a Droplet, you can try restarting MySQL or PostgreSQL depending on what you’re using. And if your server is low on resources, it might be running out of connections, especially under load.

You can check the status of your database by running sudo systemctl status mysql or sudo systemctl status postgresql depending on what you’re using.

Another option is to move to a managed database service like DigitalOcean’s Managed Databases so you don’t have to worry about the database server itself:

https://docs.digitalocean.com/products/databases/

If you’re not sure, feel free to share a bit more about your setup (what app you’re running, what kind of database, hosting details).

- Bobby

KFSys
Site Moderator
Site Moderator badge
May 29, 2025

Heya,

  • Database server is down

  • Incorrect DB credentials in config.php

  • Too many open database connections

  • The database server is out of resources (RAM/CPU)

  • Database permissions or networking issues

Those are the possible causes of the problem you are seeing with the first 2 being the most common.

Check if the database server is running

If you’re using MySQL or MariaDB, run:

sudo systemctl status mysql
# or
sudo systemctl status mariadb

If it’s not running, start it:

sudo systemctl start mysql

Check database credentials in config.php

Open your app’s config.php file:

nano /path/to/your/app/config.php

Look for:

$CFG->dbhost = 'localhost';   // or an IP address
$CFG->dbname = 'your_db_name';
$CFG->dbuser = 'your_db_user';
$CFG->dbpass = 'your_db_password';

Verify that:

  • Host is correct (often localhost, but not always)

  • User and password are accurate

  • Database exists

Test DB connection manually

Run this in the terminal:

mysql -u your_db_user -p your_db_name
  • If this fails, double-check your username/password and permissions.
alexdo
Site Moderator
Site Moderator badge
May 29, 2025

Heya, @ismailjamil

If your disk is full, the database may crash or refuse connections. Run:

df -h

If usage is near 100%, you can clean up logs or unused files.

Also look at MySQL’s error log will give you the real reason why it’s not starting or failing connections:

sudo cat /var/log/mysql/error.log

Regards

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.