Back Up and Restore MySQL Databases with Mysqldump

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 Back Up and Restore MySQL Databases with mysqldump command line. I hope will this your helpful. Thank you for reading the DevopsRoles page!

,

About HuuPV

My name is Huu. I love technology and especially Devops Skill such as Docker, vagrant, git so forth. I likes open-sources. so I created DevopsRoles.com site to share the knowledge that I have learned. My Job: IT system administrator. Hobbies: summoners war game, gossip.
View all posts by HuuPV →

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment moderation is enabled. Your comment may take some time to appear.

This site uses Akismet to reduce spam. Learn how your comment data is processed.