Table of Contents
Introduction
In this tutorial, How to backup and restore MySQL or MariaDB databases from the command line using the mysqldump command line.
Backup a Single MySQL Database
Use mysqldump command line to back up a single MySQL Database. Used user root to backup to save to folder as below:
mysqldump -u root -p LINUXOPERATINGSYSTEM > /tmp/LINUXOPERATINGSYSTEM-$(date +%Y%m%d).sql
Restore a Single MySQL Database
Now, I will restore a single MySQL Database to a new host MySQL Database.
Example my Database
- New Database: LINUXOPERATINGSYSTEM
- File dump: /tmp/LINUXOPERATINGSYSTEM-$(date +%Y%m%d).sql
mysql -u root -p -e "create database LINUXOPERATINGSYSTEM";
mysql -u root -p LINUXOPERATINGSYSTEM < /tmp/LINUXOPERATINGSYSTEM-$(date +%Y%m%d).sql
Mysqldump Command Syntax
mysqldump <OPTIONS> > dumpfile.sql
- OPTIONS: The mysqldump options for Backup and Restore
- dumpfile.sql: The dump (backup) file for MySQL Database
Conclusion
You have to Back Up and Restore MySQL Databases with mysqldump command line. I hope will this your helpful. Thank you for reading the DevopsRoles page!