Error Establishing a Database Connection

LPTechs

New member
There will come a time in every website that uses a database life where you will see the error

"Error Establish a Database Connection"

Don't worry, this is more common than you think. All this means is (and I am sure you can guess by the error) that someone broke the connection from a configuration file or an index file to the database.

Here are a few things you want to check to get your Database and website connected again.

1. In most websites that are connecting to a Database, there will be some kind of configuration file or something that holds the credentials to connect to the database. The first thing you want to check is to make sure the name of the database in the configuration file is the same of the database you have created for this website. You can locate the name of the database file by going into your control panel or system panel for your account and finding the location of your "MySQL Databases." You will need to know this for the next options.

2. If you have confirmed that the database name is the same and correct, you want to make sure now that the password is synced correctly in the system. After locating where your "MySQL database" is, there will be an option that says "Password" or "Change Password." You will want to change this and save it in a safe spot. Go back into your configuration file and looks for something that says "pass" or "password" for your database. Replace the password in the quotation mark and hit save. You database password is now synced. You do not need to save the password in a password file or anything like that.

3. If you are still seeing the error after you have tried the above 2 options, then you want to make sure that the database IP is correct, or try another option to see if the system requires a different connection. You will see something that says "localhost." This is the most common type of connection to the database since it is on your local hosting provider's server. You can try to change this to "127.0.0.1" and see if the error is fixed.


If none of the options work, then you need to contacting the company that hosts your website and ask them to check the coding to make sure nothing is exploited or corrupted in the script.

Please let us know if you have any more questions.
 
3. If you are still seeing the error after you have tried the above 2 options, then you want to make sure that the database IP is correct, or try another option to see if the system requires a different connection. You will see something that says "localhost." This is the most common type of connection to the database since it is on your local hosting provider's server. You can try to change this to "127.0.0.1" and see if the error is fixed.


agree. that error message usually because the mysql username/password not correct

or connect to the host try using localhost/127.0.1.1
 
I will add some more points. Many times we used to migrate/transfer the websites from the one server to another. That time, there is possibility that the password format of first server is not matching with the password format on the other server so you will need to update the password of database user in the format that is accepted by the current server.

Also if there is high load on the server due to number of MySQL processes running simultaneously then your website used to display the error in establishing the database connecting message. In this case, we used to kill the processes which are consuming the high resources on the MySQL server.

If the SQL server is down or service is down then you get the provided message.
 
Top