Export or Backup All MySQL Databases From The Command Line

0
1206

Exporting or Backing up all MySQL Databases is a very common task you will need to accomplish at some point in your development experience.

MySQL provides a very handy Command Line tool called mysqldump (pronounced MySQL Dump) which does exactly that.

Some general reasons would be:
Performing periodic MySQL Database Backups.
Moving MySQL databases from one server to another.
Innodb or other DB engine maintenance.

Backing up all MySQL Databases into one .SQL

Running this command is both the same for Linux as well as Windows and we assume that you are on the same server(locahost), if you are connecting to another server you can specify the server hostname or IP by also specifying the “-h hostname” parameter.

mysqldump -u username -p --databases > databases.sql

While it is not generally recommended, some people also like specifying the password in the command line.

mysqldump -u username -p password --databases > databases.sql
Linux Specific Commands

If you would also like to gzip compress the file in one go then you can run the following command on linux.

mysqldump -u username -p password --databases | gzip > databases.sql.gz

LEAVE A REPLY

Please enter your comment!
Please enter your name here