WordPress Error Database Connection

The possible causes of “Error establishing a database connection” usually are:

  • Hostname, incorrect user name or password
  • MySQL server stopped
  • Correct data connection but the tables are empty
  • Corrupt tables

Incorrect data connection

Open your wp-config.php file and look for the access data that are being used on wp-config.php:
define('DB_NAME', 'wordpress_9');
define('DB_USER', 'wordpress_0');
define('DB_PASSWORD', 'G0D5L_2anl');
define('DB_HOST', 'localhost:3306');

Now from SSH we’ll connect using the data of the wp-config.php file:
mysql -uwordpress_0 -pG0D5L_2anl -hlocalhost -P3306 wordpress_9 
After inserting the password, something like below should come up:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 1657
Server version: 5.5.52-MariaDB MariaDB Server

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [wordpress_9]>

MySQL server stopped

If trying the previous step, it shows an error like ‘MySQL is not working’ or ‘MySQL is stopped’, we´ll connect through SSH and execute:

service mysqld start
service mysql start

Empty tables

In case that the connection data are correct and  ‘Error establishing a database connection’ keeps on showing up, we have to review that our tables aren’t empty.

Corrupt tables

To fix the problem of corrupt tables, we’ll edit the wp-config.php adding:
define('WP_ALLOW_REPAIR', true);
To go on, go to www.midominio.com/wp-admin/maint/repair.php and an assistant like this one will show up:

WordPress Error Reparar Tablas

WordPress Error Restore Tables


Once we have repaired the tables, we have to eliminate the line “define(‘WP_ALLOW_REPAIR’, true);” of the wp-config.php file.


To write a comment on this article, fill out the form below. Fields marked with an asterisk (*) are required.