Getting your database to work after restoring it
After you have restored your database, you might get an error when trying to view your webpage. Examples:
Error establishing a database connection
Warning: mysql_connect(): Access denied for user: 'user1_name1@localhost' (Using password: YES) in /home/joe123/public_html/catalog/includes/functions/database.php on line 19
Unable to connect to database server!
What this means is that your database now exists in cPanel, but your website cannot communicate with it. Now is time to assign a database username and reconfigure your website's database settings.
- Login to your cPanel and click the "MySQL Databases" icon.
- Scroll down till you see MySQL Users > NewUser.
- The username can be anything you want. For this example, we will choose gatorboy.
- Pick any random password. You won't need to commit this to memory, so go nuts. For this example, nvGHdCC0dCMz can be our database password. Copy the password and keep it ready. Now enter the password twice and then press the "Create User" button.
The user has now been added, but it has not been assigned to a database.
- In the same area under MySQL Users you will see a second section called Add User To Database.
- Choose the username you just created from the drop down. (Notice that cPanel will automatically prepend your database name with your cPanel username. For this example, we get joe123_gatorboy.) Copy this username and keep it ready.
- Next, choose the name of your database and click the "Submit" button. If you don't know which database name to use, skip this step for now.
Now you need to locate your database configuration file.
- If you have a general error message like the first example, then use our config files article to determine the location.
- If you have a specific error message like the second example, then the error tells us the location. In our example the error says "in /home/joe123/public_html/catalog/includes/functions/database.php on line 19". That is where you need to go.
It is finally time to reconfigure your website's database settings.
- Go to the configuration file and choose to Edit.
- Look in the code for a place where your database name is defined. Here is the example of what we see:
- The database name is very important; it must have your new cPanel name in the first part. Update the part before the underscore, but change nothing after the underscore. Example:
define('DB_NAME', 'joe123_wrdp1');If you skipped step 3 while assigning the user to the database, you must go back and complete that step. The value you have for your database name is the correct name to choose in the second drop down. (Don't forget to click Submit.)
- Next, get the database username and password you set aside and replace the ones in the file. Example:
define('DB_USER', 'joe123_gatorboy');This is the last time you will need this username and password, so you don't need to keep a copy anymore.
- The host name is always 'localhost', so make that change if needed.
- Save the file and you are done! Refresh your webpage to see if it works.