The "Error establishing a database connection" is a critical error that renders your website inaccessible to users. This error occurs when WordPress cannot connect to the database. Troubleshooting this error can be challenging for beginners since various factors may cause it. However, before reaching out to our customer support team, there are several steps you can try.
Steps to troubleshoot the database connection error
Restore a backup of the site
- If your site is down due to this error, restoring a previous working version can resolve the issue. At 10Web, we automatically back up every site daily. You can access these backups from your dashboard and restore a functional version of your website.
Check database credentials in the wp-config.php file
- The wp-config.php file holds essential WordPress settings, including your database connection details. Incorrect database credentials can prevent WordPress from connecting to the database. To check and correct this:
- Connect to your site via SFTP. If you are unsure how to connect via SFTP, please refer to our guide.
- Navigate to the WordPress root directory by clicking on web/wp-live.
-
Right-click on wp-config.php and choose View/Edit.
Look for the following lines:
CODE ELEMENT
// ** MySQL settings - You can get this info from your web host ** ///** The name of the database for WordPress */
define( 'DB_NAME', 'database_name_here' );
/** MySQL database username */
define( 'DB_USER', 'username_here' );
/** MySQL database password */
define( 'DB_PASSWORD', 'password_here' );
/** MySQL hostname */
define( 'DB_HOST', 'mysql.10web.site' );
- Ensure these values match the database credentials found in your 10Web dashboard under Hosting Services > Credentials > Database Access.
- If the credentials do not match, update them accordingly and save the file.
Note:
Advanced users can also edit the wp-config.php file via SSH using the vim command.
Contacting customer care
If these steps do not resolve the issue, please reach out to our Customer Care team for further assistance.
Important:
Always backup your site before making any major changes, especially when editing configuration files.