Backing Up and Transferring MySQL Tables: Difference between revisions

From Littledamien Wiki
Jump to navigation Jump to search
(Created page with "==Copy entire database== Back up an entire database: <syntaxhighlight lang="bash"> $ mysqldump -u user -p db-name > db-name-backup-YYMMDD.sql </syntaxhighlight> Copy the back...")
(No difference)

Revision as of 20:20, 21 March 2012

Copy entire database

Back up an entire database:

$ mysqldump -u user -p db-name > db-name-backup-YYMMDD.sql

Copy the back up to a new database

$ mysql -u user -p db-name < db-name.outdb-name-backup-YYMMDD.sql

Copy a table from one database to another

Create a table maintaining the engine, primary keys and indexes

CREATE TABLE `dst_database`.`table_name` LIKE `src_database`.`table_name`;

Populate table with data from a table in another database:

INSERT INTO `dst_database`.`table_name` SELECT * FROM `src_database`.`table_name`;

Note that these two statements are not supported by all MySQL Engine types though. InnoDB being one of them in MySQL ver 5.x