Mysql text import and export data

Source: Internet
Author: User
Tags mysql text

Mysql text import and export data to establish a test table. Prepare the data. First, create a table for testing to indicate the student information. The fields include id, name, age, city, and salary.
The Id and name cannot be empty. Www.2cto.com create table person (id int not null auto_increment, name varchar (40) not null, city varchar (20), salary int, primary key (id )) engine = innodb charset = gb2312; then write a text file for import: c: \ data.txt. Zhang San 31 Beijing 3000 Li Si 25 Hangzhou 4000 Wang Wu 45 \ N 4500 Xiao Ming 29 Tianjin \ N www.2cto.com each item is separated by a Tab key. If this field is NULL, \ N is used. 2. import data using the input command. Load data local infile "c:/data.txt" into table person (name, age, city, salary); local indicates local. After execution, we can see that the NULL data is correctly imported. 3. Export data now export the table as a text file: c: \ data_out.txt. The Code is as follows: select name, age, city, salary into outfile "c:/data_out.txt" lines terminated by "\ r \ n" from person; lines terminated by "\ r \ n" indicates that each row (that is, each record) is separated by \ r \ n, and \ r \ n is the line break of the window system. The imported data_out.txtis exactly the same as that of data.txt. 4. Running Environment Windows vista home basic MySQL 5.1.34-community 5. Note that the separation between fields and records (rows) is \ t (Tab) and \ n by default. But it can be changed, for example, fields terminated by ',' -- use field to separate lines terminated by ';' -- use record; in addition, note that the line breaks of other operating systems may be different from those of windows.
 

Related Article

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.