Database error while importing a back up file.

Hi there,

I am working on a client's website and I revamped the website but he wants me to import the old website via a backup file to the /old/ directory. I have uploaded the WP folder from the back up file to the /old/ directory in the public_html of the main website.

But when I do that, and try to access it by putting /old/ at the end of the website URL, I see a database error that reads "Error establishing a database connection."

I tried to create a new database and a new database user and linking both and then entering the details in the wp-config.php but when I did that, I got a very new and clean installation of WordPress rather than the old WordPress website.

Can you please help me out? I can provide you the cPanel login details.

Thanks,
Qureshi

  • Kris Tomczyk

    Hi TheQureshi

    Hope you are doing good today.

    From what you wrote you just move files from backup to /old/ folder on your FTP via cPanel.

    You may have missed an important step which is connect old site to correct database which is also need to be copy.

    But when I do that, and try to access it by putting /old/ at the end of the website URL, I see a database error that reads "Error establishing a database connection."

    This part mean DB_NAME, DB_USER, DB_PASSWORD or DB_HOST are incorrect, maybe this site was on another hosting and DB_HOST is different or DB_NAME, DB_USER, DB_PASSWORD was change.

    I tried to create a new database and a new database user and linking both and then entering the details in the wp-config.php but when I did that, I got a very new and clean installation of WordPress rather than the old WordPress website.

    Yes, if you connect any old site to fresh database with no data WordPress will treat this as a new installation.

    Please follow this small guide below and skip steps which you already made:

    1. Move backup of your site to /old/ folder
    2. Log in to your phpmyadmin in cPanel and connect to correct database which was connect to this backup site
    3. Export this database to your PC
    4. Create a fresh database in your cPanel
    5. Using notepad or notepad++ open on your PC your database file (.sql file) and replace all link from
    your_domain_name.com
    to
    your_domain_name.com/old
    6. Import this edited file to your fresh database in phpmyadmin
    7. Edit wp-config.php file in /public_html/old/wp-config.php and connect your "old" site to this new database changing those values:

    define('DB_NAME', 'database_name_here');
    define('DB_USER', 'username_here');
    define('DB_PASSWORD', 'password_here');
    define('DB_HOST', 'localhost');

    8. Launch your site

    I hope this help :slight_smile:
    Kind Regards,
    Kris