Tech Blog
Tech Nooz and How Tooz
MySQL – Copy Individual Tables Over From Another Database (While preserving keys, etc.)
Categories: MySQL

This works great and it preserves all of the data that you’ll need. old_database should be changed to the name of the database that you want to copy tables from. I hope that you find this helpful.

MySQL Copy tables from a different database

//CREATE THE NEW TARGET DATABASE
create database new_database;

//CHANGE TO THE NEW DATABASE
use new_database;

//Create each table that you want to duplicate into the new database
CREATE TABLE address_book LIKE old_database.address_book;

//Populate the new table
INSERT INTO address_book SELECT * FROM old_database.address_book;

//VERIFY THE RESULTS
describe address_book;

select * from address_book;

Comments are closed.