Hello dear readers of the TMDHosting blog. It is me Samuel Monard and this week I’d like to show you what to do when your website displays the ominous error “Error establishing a database connection”.
The easiest way to get this issue fixed is to submit new support ticket to our Genius Support Team. We will be more than glad to assist you and resolve the experienced difficulty within couple of minutes.
However, I am sure there are many of you who are always ready to learn something new and would want to fix it themselves. Here are the exact steps to follow to examine and localize what exactly is causing the issue.
Usually the “Error establishing a database connection“ message is being displayed instead your website and it looks really scary to the unexperienced user.
However, there is nothing to worry about because this issue can usually be resolved in the matter of minutes.
Please, bear in mind that the error message can be different for the various CMS which you might be using.
The most common reasons for this issue might are the following:
1) Incorrect configuration of your application.
2) Missing MySQL username or database.
3) The maximum number of simultaneous connections to the MySQL server has been reached from your account.
With the above possible reasons in mind you can easily track what is causing the issue yourself.
If your website is using MySQL database, this automatically means that you are either using some CMS software or you have custom built application and as such the same should have its own configuration file where the MySQL credentials should be properly set.
Here are the names of the config files of some of the most popular CMS applications:
Joomla – configuration.php – The file is located inside the application public_html folder.
WordPress – wp-config.php – The file is located inside the application public_html folder.
Magento – local.xml – The file is located inside the public_html/app/etc/ folder.
Moodle – config.php – The file is located inside the application public_html folder.
Prestashop – settings.inc.php – The file is located inside the application public_html/config/ folder.
CSCart – config.php – This application has two config.php files. One located inside the application public_html folder and one inside its admin folder.
To verify that your application is properly configured, you should examine your application configuration file. If the MySQL database host, database username, database name values are properly set then you should proceed to the second step of checking your cPanel -> MySQL Databases.
If the config file of your applications has not been recently modified you should be heading to your cPanel -> MySQL Databases. There you should check if the database username and database file are present.
If your database username is missing it can be easily recreated by creating new database user on the same page. Please, make sure it is created with the same password as the one in your application configuration file to prevent further difficulties. When you create the database user you should add it to your old database. This can be done from the “Add User To Database” field. Once you select your new database user and your old database from the drop down fields click on the “Add” button. You will be displayed with page where you should manage the new username privileges. All you have to do is to select “All Privileges” and click on the “Make Changes” button. That’s it now your applications should be able to gain access to its MySQL database and your website should be displayed properly.
However, in case your website database is missing this would recreate your website database and restore its content from some previous backup. Luckily, on our shared hosting servers your MySQL databases are backed up every day and we keep 5 backups for 5 days before the next backup is generated. All you have to do is submit a new support ticket to our Genius Support Team and we’ll gladly restore your database from its previous backups.