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:
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.
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
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.
To fix the problem of corrupt tables, we’ll edit the wp-config.php adding:
To go on, go to www.midominio.com/wp-admin/maint/repair.php and an assistant like this one will show up:
Once we have repaired the tables, we have to eliminate the line “define(‘WP_ALLOW_REPAIR’, true);” of the wp-config.php file.