Wednesday, March 31, 2010

Use mysqldump to copy tables from one schema to another

The following command is great for copying tables from one schema to another within the same MySQL database:
mysqldump -u DB_USERNAME_HERE --password="DB_PASSWORD_HERE" --opt SCHEMA1_NAME_HERE TABLE_NAME_HERE | mysql -u root -p SCHEMA2_NAME_HERE
Be aware that this will overwrite existing tables and data which is usually exactly what you want.
To copy to a schema on a different system:
mysqldump -h HOST_IP_HERE -u DB_USERNAME_HERE --password="DB_PASSWORD_HERE" --opt SCHEMA1_NAME_HERE TABLE_NAME_HERE | mysql -u root -p SCHEMA2_NAME_HERE

0 comments:

Post a Comment