How do you replicate mysql table?

PHPMyAdmin or mysqldump

I'm assuming you mean *duplicate* not replicate. Replicating refers to having the same data on multiple machines for either performance or backup issues. The following solution is for duplicating a table.

I'm by no means a MySQL genius, but I've worked with MySQL for a while.

If you have PHPMyAdmin installed, the easiest thing to do is go to your table, click Operations, fill in "copy table to..."

If you don't have PHPMyAdmin, the easiest way I can think of is using mysqldump, editting the dump file, then importing the table:

> mysqldump -p DatabaseNameToGetFrom TableName > SomeFileName.dump > pico/ee/edit/vi/emacs/YourFavoritePlainTextEditor SomeFileName.dump

Use a find and replace on the old table name and change it to the new tablename, save it, exit the editor then run this command:

> mysql -p -D DataBaseNameToPutInto < SomeFileName.dump

That should do it fine.

Another way is this command:
create table NEW select * from OLD;

Then use:
show create table OLD;
alter table NEW add primary key (this,that);
Then add other keys as necessary;

 

Improve Answer Discuss the question "How do you replicate mysql table?" Watch Question

First answer by ID2150292265. Last edit by Sasalehall. Contributor trust: 1 [recommend contributor]. Question popularity: 69 [recommend question]


Research your answer:

Can you answer other questions about programming?

Answers.com > Wiki Answers > Categories > Technology > Computers > Computer Programming > How do you replicate mysql table?

Our contributors said this page should be displayed for the questions below. (Where do these come from)
If any of these are not a genuine rephrasing of the question, please help out and edit these alternates.
How to replicate mysql table?  How much table that mysql database handel?