-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,438
  • 68
  • 55
  • 126
Erik
  • 5,533
  • 26
  • 67
  • 113

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
Tiberiu-Ionuț Stan
  • 5,311
  • 6
  • 36
  • 65
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,621
  • 1
  • 24
  • 30