To copy a table structure and all of its data:

CREATE TABLE new_table LIKE old_table;
INSERT INTO new_table SELECT * FROM old_table;

To create a new database and copy a table structure and data from another database:

CREATE DATABASE new_database;
USE new_database ;
CREATE TABLE new_table LIKE old_database.old_table ;
INSERT INTO new_table SELECT * FROM old_database.old_table;

With the above query you can also use a WHERE statement to select only specific data rather than copy all of the data.

CREATE DATABASE new_database;
USE  new_database ;
CREATE TABLE  new_table  LIKE  old_database.old_table ;
INSERT INTO  new_table  SELECT * FROM  old_database.old_table WHERE column1 = 1;

Was this answer helpful? 0 Users Found This Useful (0 Votes)