Backing Up & Restoring a MySQL Database from the Command Line

Table of Content

A quick guide on using the MySQL CLI to manage your database backups.


Backup

Use MySQLDump to backup the database:

mysqldump -u [user_name] -p [database_name] > [file_name].sql

Where:

  • [user_name] is the name of your MySQL user
  • [database_name] is the name of your database
  • [file_name] is the name of your output file

Restore

Use the MySQL command line interface to restore from the backup you made previously:

mysql -u [user_name] -p [database_name] < [file_name].sql

Where:

  • [user_name] is the name of your MySQL user
  • [database_name] is the name of your database
  • [file_name] is the name of your input file