MySQL replication table structure, table data

Source: Internet
Author: User

1, copy table structure and data to new Table
CREATE table New Table select * from old table
This method will copy all the contents of oldtable, of course, we can use delete from newtable;
However, one of the worst aspects of this approach is that the new table has no properties such as primary key, Extra (auto_increment), and so on. You need to use "alter" to add, and it's easy to mistake.
 
 
2, copy table structure to new Table
CREATE table New Table select * from old table where 1=2
or CREATE table new table like old table
 
 
3, copy data from old table to new table (assuming two table structure)
INSERT into new table select * from old table
 
 
4, copy data from old table to new table ( Suppose two table structures are different)
INSERT into new table (Field 1, Field 2,.......) SELECT Field 1, Field 2,...... From old table
 
 
5, table 1 structure can be copied to table 2
SELECT * into table 2 from table 1 WHERE 1=2
 
 
6, You can copy all table 1 contents to table 2
SELECT * to table 2 from table 1
 
 
7, Show create table old table;
This will list the creation commands for the old table. We only need to copy the command, change the name of the table, we can create an identical table
 
 
8, mysql mdump
Use mysqldump to dump the table, change the name, and then go back or run the

directly on the command line.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.