Welcome to Tech A Byte Solutions. Your Trusted Web Companion with Total Web Solution!!

×

Welcome to Tech A Byte Solutions. Your Trusted Web Companion with Total Web Solution!!

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;

Back to Top
error: Alert: All Contents of TechAByte Solutions are protected !!