Migrate data in mysql from old schema to new schema
We have recently improved the schema of our production database, changing column names and indexes etc. We also changed the storage engine to InnoDB to make use of transactions and foreign keys.
What is the best way to i开发者_如何转开发mport the data from the old schema into the new schema? Bare in mind that column names have changed (including primary keys).
As if you have changed the column names you may create out files and import.
SELECT * FROM old-table INTO OUTFILE '/path/to/filename.txt' FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n'
and then you may do LOAD Data:
LOAD DATA INFILE '/path/to/filename.txt' INTO TABLE new-table FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';
References:
- http://dev.mysql.com/doc/refman/5.0/en/select.html
- http://dev.mysql.com/doc/refman/5.0/en/load-data.html
Otherwise if possible following will do the job as far as number of columns are same:
insert into new-table select * from old-table;
If number of columns are not same then:
insert into new-table select col1,col2,... from old-table;
精彩评论