MySQL and MariaDB include two command-line tools that you can use to quickly backup and restore databases. The mysqldump tool is used to export the contents of a database to a text file, while the mysql client can be used to import data from a text file into a MySQL/MariaDB database.
To backup a MySQL/MariaDB database from the command line, follow these steps:
-
Launch a new Windows command shell using the "Shell" button in the XAMPP control panel.
-
Use the command below to export the contents of the selected database. In this example, we’re backing up the WordPress database, which is named bitnami_wordpress, to a file named bitnami_wordpress.sql. This text file is your backup, so store it safely!
mysqldump --user=root --password="" bitnami_wordpress > bitnami_wordpress.sql
At a later point, you may wish to restore the database. To restore the data to a fresh MySQL/MariaDB database from the command line, follow these steps:
-
Launch a new Windows command shell using the "Shell" button in the XAMPP control panel.
-
Use the mysql client to create a new, empty database to hold your data. In this example, the new database is named myblog.
mysql --user=root --password="" -e "CREATE DATABASE ticket"
Remember to use the correct database access credentials in the command. On a fresh XAMPP installation without any changes, you can usually log in as root with a blank password.
- Use the mysql client to import the contents of the backup file into the new database.
mysql --user=root --password="" --database=myblog < bitnami_wordpress.sql
The command-line client will now import the data from the backup file.