MySQL – How to Export and Import tables with the Command Line
2 commands I use often throughout the day is importing and exporting large databases into MySQL VIA the command line. Here is how I do it where “USERNAME” is your username, “PASSWORD” is your password and “DATABASE” is your database name.
To Export:
1 |
mysqldump -uUSERNAME -pPASSWORD DATABASE | gzip -c > ~/dump_2010-06-14.sql.gz |
To Import:
1 |
mysql -uUSERNAME -pPASSWORD DATABASE < database.sql |
Also, you may have a large database that may give you errors while importing. You can use this command to force the import without warnings or errors:
1 |
mysql -f -uUSERNAME -pPASSWORD DATABASE < database.sql |
Great! Definitely going to keep this in my toolbox!
Thanks for this short but incredibly useful piece of code!