How to resolve WordPress database connection error locally (XAMPP)

Solution 1:

If you have your old database file (.sql), you can restore it as follows:

To import the database:

  • Open phpMyAdmin in your browser: http://localhost/phpmyadmin
  • Select the database you want to import into. (If the database doesn’t exist, create a new one.)
  • Click the Import tab in the top menu and upload your .sql file.

To take a backup of your database in XAMPP:

  • Open phpMyAdmin: http://localhost/phpmyadmin
  • Select the database you want to back up.
  • Click the Export tab in the top menu and save the backup file.

Solution 2:

If your old drive was completely wiped and you weren’t using any WordPress backup plugin, unfortunately, you won’t be able to fully rebuild your site. The WordPress database stores not only your content (posts and pages) but also critical information about which plugins were used, making it essential for a complete site restoration.

For future reference, always export your database to a file (e.g., .sql) so it can be imported on a new server or PC. You can do this using:

  • A WordPress backup plugin
  • phpMyAdmin (in XAMPP)
  • Third-party applications like Sequel Pro or MySQL Workbench

Even without the database, if you still have your images, CSS files, and other static resources, you at least have the basic content to start rebuilding your site.

Solution 3:

If you need to reinstall your WordPress site with a new database because the previous one was lost, it’s essential to regularly back up your site to prevent future data loss.

A free and reliable plugin for this is UpdraftPlus:

UpdraftPlus: WP Backup & Migration Plugin

It allows you to back up your database, files, and themes, and easily restore them when needed.