MYsql data text export and import _ MySQL

Source: Internet
Author: User
Export and Import bitsCN.com in MYsql data text format

MYsql data text export and import

I. query the table structure

Mysql> desc province;

+ ----------- + ------------- + ------ + ----- + --------- + ---------------- +

| Field | Type | Null | Key | Default | Extra |

+ ----------- + ------------- + ------ + ----- + --------- + ---------------- +

| Id | int (11) | NO | PRI | NULL | auto_increment |

| Name | varchar (32) | NO | NULL |

| CountryId | int (11) | YES | MUL | NULL |

+ ----------- + ------------- + ------ + ----- + --------- + ---------------- +

The data in the two-dimensional table is exported as a two-dimensional file (.txt)

SQL code

Select id, name, countryId

Into outfile "d:/data_out.txt"

Lines terminated by "/r/n"

From province;

Export result:

1 Beijing 1

2 Shanghai 1

3 Tianjin 1

4 Chongqing 1

5 Heilongjiang 1

6 Jilin 1

7 Liaoning 1

......

III. import text files to the database

SQL code

Load data local infile "d:/data_out.txt"

Into table t_province (id, name );

Import result:

Mysql> select * from t_province;

+ ---- + -------- +

| Id | name |

+ ---- + -------- +

| 1 | Beijing |

| 2 | Shanghai |

| 3 | Tianjin |

| 4 | Chongqing |

| 5 | Heilongjiang |

BitsCN.com

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.