Copying MySQL data

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;

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

MySQL Trouble shooting

Try checking for Typos by printing out the query that is getting sent to MySQL Server from your...