How to copy data from a MySQL table to a new table

Source: Internet
Author: User
I believe that you will not be familiar with the operation of copying data from a MySQL table. The following describes how to copy data from a MySQL table to a new table. 1. MySQL copies the table structure and data to the new table CREATETABLE new table SELECT * FROM old table 2. Only copies the table structure to the new table CREATETABLE new table SELECT * FROM old table WHERE

I believe that you will not be familiar with the operation of copying data from a MySQL table. The following describes how to copy data from a MySQL table to a new table. 1. MySQL copies the TABLE structure and data to the new table create table new table select * FROM the old TABLE 2. Only copies the TABLE structure to the new table create table new table select * FROM the old TABLE WHERE

I believe that you will not be familiar with the operation of copying data from a MySQL table. The following describes how to copy data from a MySQL table to a new table.

1. MySQL copies the table structure and data to the new table

Create table new TABLE
SELECT * FROM old table

2. Only copy the table structure to the new table

Create table new TABLE
SELECT * FROM old table WHERE 1 = 2
That is, make the WHERE condition invalid.
Method 2: (mysql of earlier versions is not supported, mysql 4.0.25 is not supported, and mysql 5 is supported)
Create table new TABLE
LIKE old table

3. copy the data from the old table to the new table (assuming the two tables have the same structure)

Insert into new table
SELECT * FROM old table

4. copy the data from the old table to the new table (assuming the two tables have different structures)

Insert into new table (Field 1, Field 2 ,.......)

SELECT Field 1, Field 2 ,...... FROM old table

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.