Many modern websites rely on databases. This is especially true of virtually any and all Content Management Systems, Blogging platforms, eCommerce platforms, application frameworks, forums, and more.
As you and your visitors use your site, your database will grow with more and more valuable data. Thus, making changes to the website, applying updates, adding plugins, migrating to another server, or general maintenance introduces an element of risk - what if the database goes missing or gets corrupted?
Fortunately, backing up a MySQL database is a straightforward task.
Backing up using phpMyAdmin
First, login to your cPanel account. Then click on the phpMyAdmin icon.
Next, on the left pane inside phpMyAdmin, click on the plus next to your cPanel username to expand the list of databases. Then click on the database you wish to backup.
The database will open on the right. Click on the Export tab.
In most cases, on the following screen, the default settings using the Quick option should be adequate for most people.
If you want to make any customisations, click Custom and more options will be presented to you. However, they're pretty advanced - if you're not sure what they do, it's best to leave them alone.
When ready, click the Go button. This will generate a .sql file, which will be downloaded to your computer. Be aware that this may take some time depending on the size of the database.
How do I restore / import the database?
As the saying goes, installation is the reverse of removal.
To import a previously exported database using phpMyAdmin:
- Create a new database to import your database to.
While you can import to an existing database, this could lead to problems, data duplications, etc. If you're not sure, it's best - and strongly encouraged - to use a new, empty database.
- Access phpMyAdmin, and open the database you intend to restore to, using the same steps above.
- Click on the Import tab.
- Under the File to Import heading, click the Choose File button and locate the file you downloaded when you exported previously. Typically, the file extension will be .sql.
If you performed a Quick export with default phpMyAdmin settings, you shouldn't need to change anything else here.
- Click the Go button. The file will upload to the server, and phpMyAdmin will attempt to restore the data to the target database.