Create and Import dumpfile or SQL datafile into mysql database


Here are few commands to easily create and import MySQL data.

To create dumpfile:
mysqldump -u USER -p PASSWORD DATABASE > filename.sql

To import dumpfile:
mysql -u USER -p PASSWORD DATABASE < filename.sql

Export MySQL database structure only:
mysqldump -u USER -p PASSWORD --no-data DATABASE > filename.sql

Export data of MySQL database only:
mysqldump -u USER -p PASSWORD --no-create-info DATABASE > filename.sql

To create dumpfile of all databases:
mysqldump -u USER -p PASSWORD --all-databases > filename.sql

To import dumpfile when either database name is not known or dump has database info:
mysql -u USER -p PASSWORD < filename.sql

USER : database username
PASSWORD : password
DATABASE : database name to which datafile is to be imported

Advertisements