I need to copy three tables and rename them in the same MySQL database. Does anyone know a statement I can execute, or do I need to export and import?
-
Consider removing the php tag and the import tag. – oxygen Jun 02 '12 at 18:16
-
You should include the MySQL version, as well as what engine you are using (InnoDB, MyISAM, Memory, etc.). – oxygen Jun 02 '12 at 18:20
2 Answers
Answer is here on StackOverflow, hidden under a database rename operation (databases can be renamed by creating a new database, then "moving" the tables).
https://stackoverflow.com/a/2298602/584490
RENAME TABLE db.table TO db.table;
From the comments: "I've just done this with an InnoDB database with 30+ tables, using the file_per_table setting, and even though some tables were 3+ million rows, it completed in < 1 second. It just seems to move the files on the storage, rather than doing anything more complicated... +2 if possible :)".
You should look into the mysql equivalent of SELECT INTO: http://dev.mysql.com/doc/refman/5.0/en/ansi-diff-select-into-table.html.
Create the new tables with the new names, then use the above method to copy the old table data to the new tables.

- 3,899
- 1
- 26
- 31