User Tools

Site Tools


backup_mysql_database_from_the_command_line

How to Back Up MySQL Databases From The Command Line



To backup a MySQL database you can use a graphical interface such as phpmysql, however this can be done quite simply from the command line.

From the command line:

First you must login to MySQL

      mysql -u root -p — (the root part assumes root is your mysql username) 


A database backup is essentially a file that contains all the tables, fields and data from your database, stored in a text file.
To perform a backup, use the following command line:

      mysqldump database_name > database_name.sql
      database name is the SQL database name (the output can be different)
      
      e.g. mysqldump gallery > gallery.sql


This command only backs up a single database, if you wish to do multiple databases then use:

      mysqldump --databases database_one database_two > two_databases.sql


This allows the backup of many databases, in to one backup file.

You can backup all databases with this command:

      mysqldump --all-databases > all_databases.sql


backup_mysql_database_from_the_command_line.txt · Last modified: 2023/03/09 22:35 by 127.0.0.1