Backing Up and Restoring MySQL Dumps!

Hi Guys who are a novice to the DevOps Industry or Experts come across instances where they need to take a backup of the database, so today my article is about how to take a MySQL Backup and to restore it. These commands are all done through the terminal where MySQL resides.

Image Courtesy — https://itsilesia.com/6-tips-that-every-mysql-user-should-know/
  1. Taking a Backup

mysqldump -u {username} –p {password} {database_name} > {dump_file.sql}

When taking this command more closely, the values within curly brackets should be replaced with appropriate values.

  • mysqldump → the command it will execute
  • -u → this should be followed with the username for the
  • -p → this should be followed by the password you can either fill it or leave it as it is with a blank, if you don't specify the password here you will be prompted to enter the password when you execute the command.
  • database name → After leaving a space for the password, the database
  • dump_file.sql → the name for the output of the file

ps — It's a best practice that you name the dump file as follows, the database name followed by the date and time it was taken and storing it inside a folder dedicated for database backups.

  • example → DatabaseName-DDMMYYYY:HHMM

2. Restoring the Backup

Initially locate where you have stored the backup, and enter the following command the values of the curly brackets should be,

MySQL -u {username} –p{password} {database_name} < {dump_file.sql}

As in the previous command,

  • MySQL → the command type to execute
  • -u → the username used for MySQL
  • -p → the valid password for the mentioned username
  • database_name → the desired database it should be restored
  • dump_file.sql → the exact file it should restore.

I hope this will be helpful to make your work efficient and easy! Stay Safe and Keep Going! Never Give Up!

Im a DevOps Engineer who is trying to enhance my knowledge as well as help my fellow DevOps acquaintances with knowledge on job related tasks!