Import And Export MySQL Command

You can work with MySQL using a GUI of some sort, which is very convenient at times. In other cases you might want something more simple and faster. The MySQL dump/import commands are great for this type of thing.

Suppose you wanted to dump, or backup, your database each night. You could add the mysqldump command to your crontab.

An simple dump command is written like this:

shell> mysqldump -u USER -pPASSWORD DATABASE > filename.sql

Or if you want to keep the password hidden you can enter the following and you will then be prompted to enter the password:

shell> mysqldump -u USER -p DATABASE > filename.sql

To import the SQL file you just created you could run the following:

shell> mysql -u USER -p DATABASE < filename.sql