MySQL Quick Reference Guide – Import and Export


Importing & Exporting a Full Table

mysql_logoExport entire table with structure and data in tact:
$ mysqldump -u root -p DatabaseName TableName > filename.sql

Import entire table with structure and data in tact:
$ mysql -u root -p DatabaseName < filename.sql;

Importing & Exporting Table Data (data only)

Export data from a table:
SELECT * FROM TableName INTO OUTFILE ‘/path/to/store/file/filename.txt';

Import data into table:
LOAD DATA INFILE ‘/path/to/store/file/filename.txt’ INTO TABLE TableName;

Export Entire Database

Export Database with all tables, structure & data in tact:
$ mysqldump -u root -p DatabaseName > filename.sql

Import Database with all tables, structure & data in tact:
$ mysql -u root -p DatabaseName < filename.sql

Leave a comment

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>