How to backup / export / import a WordPress database
There are multiple, quick and easy ways to backup your websites database. In this article we’ll look at 2 different options inside of GridPane:
- Exporting via phpMyAdmin
- Exporting via WP CLI
There are also popular plugins you could use such as All in One WP Migration, UpdraftPlus, WP Database BackupWP Migrate DB, and BackWPup.
Exporting via phpMyAdmin
If you’re database is small, phpMyAdmin should work perfectly well for exporting and importing your database. It’s quick and you can do it right inside your GridPane account.
In your account, open up phpMyAdmin by clicking the database icon next to your website.
Inside phpMyAdmin, click “Databases” at the top of the page.
In the left hand side bar you can see the databases available. Select your websites database (in this example the website is “waas.monster”.
Once inside your database, scroll down to the bottom and check the “Check all” box, and then select the export option from the dropdown to the right of the check box.
phpMyAdmin will take you to a new page as shown below. Click “Go” and it will automatically start the download of your database.
Importing via phpMyAdmin
Now we need to import the database. Open up phpMyAdmin like in the step above. In the menu at the top, click on “Import“.
Click the “Choose file” button and add your database, then scroll to the bottom of the page and click “Go“.
This may take awhile depending on the size of your database, but you’ll see a success screen once complete.
Exporting via WP CLI
STEP 1. CONNECT TO YOUR SERVER
For this you’ll need to connect to your server. Please see the following articles to get started:
Generate your SSH Key:
Generate SSH Key on Windows with Putty
Generate SSH Key on Windows with Windows Subsystem for Linux
Generate SSH Key on Windows with Windows CMD/PowerShell
Add your SSH Key to GridPane:
Add/Remove an SSH Key to/from an Active GridPane Server
Connect to your server:
Connect to a GridPane server by SSH as Root user.
STEP 2. BACKUP YOUR DATABASE
Creating a backup of your database with GP-WP-CLI is quick and easy.
Run the following command to backup your database (switching out “site.url” for your domain name:
gp wp site.url db export /var/www/site.url/htdocs/name_of_backup.sql --all-tablespaces --add-drop-table
For example:
gp wp gridpane.com db export /var/www/gridpane.com/htdocs/dbaug2020.sql --all-tablespaces --add-drop-table
Importing via WP CLI
If your database backup isn’t already on your server you can upload via SFTP into your htdocs folder.
Next, navigate there with:
cd /var/www/site.url/htdocs
Now in the folder where our database is located we can run the following GP-WP-CLI command to import it:
gp wp site.url db import database.sql