Dumping a Single MySQL Table

I recently needed to test out some new code on my local version of a client's site. I ran into a problem, because keys and information that I needed for the testing were in the live version of the database, but not in my version. I needed to import new data, but this was a huge database, so I only wanted the one table rather than the entire database.

I could use phpMyAdmin for the export, and for the import, but while it is a great tool, it can be as slow as molasses when it comes importing data, not to mention the file size and execution time limits that can be a wall

In this case the best solution for me was mysqldump for the export, and the mysql command line for the import. While I had used mysqldump before, I was not familiar with the command switches to use to accomplish a single table dump. The switches available are myriad, and their description often cryptic. Here are the commands needed to export and import a table.

To export

mysqldump -u -p database_name table_name > /path/to/file/table_name.sql

To import

mysql -u -p database < /path/to/file/table_name.sql