Backup MySQL database into an .sql file from the terminal

June 08, 2013 | 1645 views | Comments

Import MySql database records from the terminal using the MySql command mysqldump, it is a quick and easy way to backup MySql database records.

For example.

mysqldump -uNAME -pPASSWORD DATABASE > database.sql


  1. NAME = the user who has access to the database.
  2. PASSWORD = the password of the user.
  3. DATABASE = the name of the database to backup.
  4. database.sql = the sql file where the records will be saved.


  • Because the path where the file is to be saved was not specified, the .sql file (database.sql) will be saved on the same location where the command is executed.
  • The same command can also be executed on windows command line.


Other Examples

Do not include the password on the command, and enter only when promted.

mysqldump -uNAME -p DATABASE > database.sql


Import specific TABLE.

mysqldump -uNAME -pPASSWORD DATABASE TABLE > database.sql


Specifically save to linux home directory.

mysqldump -uNAME -pPASSWORD DATABASE > /home/database.sql


Specifically save to windows drive D.

mysqldump -uNAME -pPASSWORD DATABASE > D:\database.sql