Sail Knowledgebase

How to Fix: Error establishing a database connection in WordPress with Sail CLI

In this short article you will learn how to quickly reset the WordPress database credentials using Sail CLI.

If you like Sail, don't forget to give us a star on GitHub!

What does the error mean?

The "error establishing a database connection" message shows up when WordPress is unable to communicate with the MySQL/MariaDB database server. This is usually a result of a broken or corrupted database configuration.

How to update the credentials with Sail CLI

Sail CLI has a handy command, which can fix this error for you:

sail db reset-password

This will generate a new database password for WordPress and update in it your MySQL or MariaDB server. It will also update the password in your production wp-config.php file.

In addition to that, the command will also make sure your other credentials (database username and database name) are correct.

After using this command, it is recommended to pull the updated wp-config.php file to your local working copy, using:

sail download wp-config.php

If you're still having trouble solving the database error with Sail CLI, visit our getting help section.