Tuesday, April 24, 2018 04:36 am EDT

MySQL Export/Import Command Line Syntax

Bri's picture

If you are like me, occasionally you find yourself working with a database that is so large it's pretty much impossible to do any importing/exporting with the GUI tools. It doesn't happen often enough for myself to have the MySQL commands memorized, so I'm putting them here so I can find them again later.

Exporting using mysqldump

mysqldump –u mysqlUser -p DatabaseName TableName > FilenameToSaveAs 

Importing the same file

mysql –u mysqlUser -p DatabaseName < FilenameToImport 

Examples using Gzip and Gunzip

This example shows dumping the indicators table from the midwest-import database into a Gzipped file called indicators.sql.gz and then importing it back in to a database called midwestfish. Both are using the root mysql user.

mysqldump -u root -p  midwest-import indicators | gzip > indicators.sql.gz

gunzip < indicators.sql.gz | mysql -u root -p midwestfish