Learn how to fix “Error establishing a database connection” when installing WordPress on a Linux server.
The most common reason for this error is using incorrect information in your WordPress config file for one or more of these settings:
- Database name
To check this information, edit the
wp-config.php file, which is located in the main WordPress directory. For example, if you are installing WordPress into http://example.com/blog the file will be in the
/blog directory (
You will find this section at the top of the file:
Before you install WordPress, you will need to change these settings:
- database_name_here – change this to the name of the database which you created for the WordPress installation.
- username_here – change this to the username for the database you created.
- password_here – change this to the password for the database user you created.
- localhost – change this to the database's host name. Note: “Localhost” will not work for WordPress on a shared hosting account. To find your database host name, check the database management panel in your IONOS Control Panel.
- Make sure you leave everything else the same, including the single quotes around the settings.
- If you made a lot of changes to the
wp-config.phpfile trying to fix the problem, it might be easier to start from scratch by copying
wp-config.phpto begin again.
- Be sure to enter the username and password correctly. These data are case-sensitive, so be sure to use the correct capitalization (upper case or lower case) for the letters.
- Follow the WordPress instructions to create the MySQL database before you try to install the software.
- It may take a few minutes for the database to be created. Be sure the database is active before you move on to the next step, installing WordPress.
Verify That the Database is Running
This problem can also occur when the MySQL or MariaDB database stops running. To check this on a Linux server, connect via SSH to the server and use the command:
ps -aux | grep mysql
This will return a list of running processes which have "mysql" in the name (including MariaDB).
The list will include the command you just ran. If MySQL is running, it will also include the MySQL process.
If MySQL/MariaDB is not running, you will only see your
grep command listed.
If the database is not running, start MySQL/MariaDB with the command:
- CentOS 7 (MariaDB):
sudo systemctl start mariadb
- Ubuntu and Debian (MySQL):
sudo service mysql startor
sudo /etc/init.d/mysqld start