mysql: Dumping single database table and restoring

Sometimes you need to dump a single table from a mysql table and restore it somewhere else. Here's what you need:

 

1. Dump the table (compress it so it will take shorter to transfer over the network)

 

mysqldump -h <HOST> -u <USERNAME> -p <DATABASE> <TABLE> | gzip > <DUMP_FILENAME>.gz

 

HOST is the hostname or IP address of the mysql server

USERNAME is a user with access to the database and table

DATABASE and TABLE are self explanatory

DUMP_FILE is the name you want for the file containing the compressed dump

 

2. Transfer the file where you need it to be, with "cp" or "scp"

 

 

cp <DUMP_FILENAME>.hz  folder/new_name

scp <DUMP_FILENAME>.hz  user@machine:folder

 

 

Tagged , , , , , . Bookmark the permalink.

Leave a Reply