14 Feb, 2010

MySQL backup from command line

Posted by: admin In: Linux|Mysql

It may be useful to make a backup of a specific database through the command line. Surely it is easier to use tools like phpMyAdmin, but in case of emergency or because you prefer use the shell, this info is certainly useful. The executable that performs the operation is “mysqldump” which is usually installed with the MySQL server.

mysqldump -h localhost -u username -p database_name > database_backup.sql

Obviously the parameters changed accordingly, localhost should be fine considering the use of the shell, while database_name username must be adjusted accordingly. After the sign > is the name chosen at your discretion. Once given the command will be prompted for a password to access the database to its content.

Can also directly produce a compressed slightly by changing the syntax as follows:

mysqldump -h localhost -u username -p database_name | gzip -9 > database_backup.sql.gz

where performs gzip compression (-9 parameter indicates the best compression possible), this is useful if you download the file through the Internet.

No Responses to "MySQL backup from command line"

Comment Form