You have the steps right, but you're missing one. You have:
- Export File (which you describe correctly in your question)
- Import File (which you also describe correctly)
You should have:
- Export File
- Modify File
- Import File
After you have exported the table, you will have a .sql file. You can go into this file and modify it. (You can open this file in any basic text editor. If you're on Windows, you can open it in Notepad by right-clicking the file icon and selecting Edit.) After some initial comments, you should have something like
DROP TABLE IF EXISTS `device`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `device` (
-- parameters, etc.
)
Note how it's dropping your table, then re-creating it? It's simple - in both of those places where the table name is, change it to your new table name.
DROP TABLE IF EXISTS `device_test`; -- note the new name
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `device_test` ( -- note the new name
-- parameters, etc.
)
There are two other places in the file that this needs to be done. One is in a LOCK TABLES
statement, and the other is in the INSERT INTO
statement. (If you wish, you could simply use a Find\Replace tool to replace all instances of the old table name with the new name.)
You can then import it, and you're all set!
EDIT: As Zak mentioned in the comments to the question, one way of doing this could be to use CREATE TABLE new_table LIKE old_table; SELECT INTO new_table SELECT * FROM old_table;
. If the two tables in question are on the same machine, etc, both methods will work. However, the dump .sql file does have portability that cannot be mimicked using SQL statements.