-3

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Erik
  • 5,701
  • 27
  • 70
  • 119

2 Answers2

0

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 :)".

Community
  • 1
  • 1
oxygen
  • 5,891
  • 6
  • 37
  • 69
0

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.

Fábio Santos
  • 3,899
  • 1
  • 26
  • 31