MySQL Export Database to File in Linux

Last updated on Dec 30, 2019 in MySQL, Linux

It is very useful to know how to export MySQL database from Linux command line by using mysqldump. You just need to know MySQL user’s username and password, and the database name that you want to export (unless you wan to export everything).

Run mysqldump

$ mysqldump -u username -p database_name > dump.sql

Here, the -p stands for password which is prompted. You could write the password after the -p, but this is considered to be bad practice since it is insecure. The command stays in the command history and therefore the password would remain visible.

The > dump.sql forwards the output to the file named dump.sql. The .sql format contains the full SQL to generate the database, so compressing it on-the-fly would be good idea. Read this next: MySQL Export Database to GZIP File in Linux