When working with MySQL databases, it’s not uncommon to encounter issues that necessitate a database restoration. XAMPP, a popular local server environment, includes tools and folders that can aid in this process. This blog will guide you through restoring your MySQL database using the backup folder included with XAMPP.
Step-by-Step Guide
1. Rename the Existing Data Folder
The first step is to ensure that we have a backup of the current data folder in case anything goes wrong. To do this, rename the mysql/data folder to mysql/data_old.
mv mysql/data mysql/data_old
Alternatively, you can manually rename the folder by navigating to the mysql directory within your XAMPP installation folder and changing the name of the data folder to data_old.
2. Create a New Data Folder from Backup
Next, we need to create a new data folder from the backup folder provided by XAMPP. Make a copy of the mysql/backup folder and name it mysql/data.
cp -r mysql/backup mysql/data
This can also be done manually by copying the backup folder and renaming the copy to data.
3. Copy Your Database Folders
Now, copy all your individual database folders from the mysql/data_old folder into the new mysql/data folder. Be careful not to copy the mysql, performance_schema, and phpmyadmin folders, as these should remain as they are in the backup.
cp -r mysql/data_old/[your_database_name] mysql/data
You can also perform this step manually by dragging and dropping the specific database folders from data_old to data.
4. Copy the ibdata1 File
The ibdata1 file contains important information about your InnoDB tables. Copy this file from the mysql/data_old folder into the new mysql/data folder.
cp mysql/data_old/ibdata1 mysql/data
Again, this can be done manually by copying the ibdata1 file from the data_old folder and pasting it into the new data folder.
5. Start MySQL from XAMPP Control Panel
Finally, start MySQL from the XAMPP control panel. Open the XAMPP control panel and click the “Start” button next to MySQL. If everything has been done correctly, MySQL should start without any issues, and your databases should be intact.
