How to backup and restore MySQL databases on Linux (Command line)

A simple and easy method for creating MySQL backups is to use the mysqldump command. This command will create a simple .sql file of an existing database, which can then be restored to any other empty MySQL database.

  1. Back up the database:-

[username] – A valid MySQL username. [password] – A valid MySQL password for the user. [database_name] – A valid Database name you want to take backup.[dump_file.sql] – The name of backup dump file you want to generate.

Sample command

  • Backup more than one database

You can backup more than one database at the same time.

# mysqldump -u [user] -p –databases [database_name_1] [database_name_2] [database_name_n] > [filename].sql
  • Backup of all databases
# mysqldump -u [user] -p –all-databases > [file_name].sql
  • Restore the backup to a local database server: –

the mysql command will let you take the contents of a .sql file backup, and restore it directly to a database. This is the syntax for the command:

# mysql -u [username] –p[password] [database_name] < [dump_file.sql]

Sample command

Build Your Website with Hostiko

From professional business to enterprise, we’ve got you covered!

Copyright ©2026 QualiSpace. All rights reserved.

A Platform

QualiSpace
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.