Getting your database to work after restoring it

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.

  1. Login to your cPanel and click the "MySQL Databases" icon.
  2. Scroll down till you see MySQL Users > NewUser.
  3. The username can be anything you want. For this example, we will choose gatorboy.
  4. 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.

  1. In the same area under MySQL Users you will see a second section called Add User To Database.
  2. 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.
  3. 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.

  1. Go to the configuration file and choose to Edit.
  2. Look in the code for a place where your database name is defined. Here is the example of what we see:
    define('DB_NAME', 'user1_wrdp1');
    define('DB_USER', 'user1_name1');
    define('DB_PASSWORD', '5Jmfde%53L');
    define('DB_HOST', 'localhost');
  3. 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.)
  4. Next, get the database username and password you set aside and replace the ones in the file. Example:
    define('DB_USER', 'joe123_gatorboy');
    define('DB_PASSWORD', 'nvGHdCC0dCMz');
    This is the last time you will need this username and password, so you don't need to keep a copy anymore.
  5. The host name is always 'localhost', so make that change if needed.
  6. Save the file and you are done! Refresh your webpage to see if it works.
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Apache Error Logs

When you check the error logs, you can see many things. Some things you can ignore: File does...

Accessing Web Disk

Web disk (also known as Web Dav) is a drag-and-drop interface which allows you to access your...

Apache Handlers (running html as php)

Apache handlers allow you to control what Apache will do with certain file types. When Apache...

Backup File Types

So, you have a backup file, but you need to know what type of backup it is so you can know what...

Copy Entire Database or Rename Database

Is there a way for me to copy an entire database in cPanel from another server? You will need...