MySQL data table import and export

Source: Internet
Author: User

Initial data (total 6 records)

Username

Userpwd

Age

Admin

Admin

18

Root

Root

18

Cat

Cat

17

Dog

Dog

15

Dog1

Dog1

15

Zhu

Zhu

21st

two creating a database, creating a table user
Create DatabaseYouku--Create a database UseYouku--Select DatabaseDROP TABLE IF EXISTS`User`;CREATE TABLE`User' (' username 'varchar( One)DEFAULT NULL, ' userpwd 'varchar( One)DEFAULT NULL, ' age 'int( One)DEFAULT NULL) ENGINE=InnoDBDEFAULTCHARSET=UTF8;//Inserting DataINSERT  into`User`VALUES('Admin','Admin', -),('Root','Root', -),('Cat','Cat', -),('Dog','Dog', the),('Dog1','Dog1', the),('Zhu','Zhu', +);--table Data ExportSELECT *  from User     intoOUTFILE'F:/user.txt'; --format the output as needed, each row of data ', ' delimited, and the string type data is enclosed in double quotes ""SELECT *  from User  intoOUTFILE'F:/user1.txt'Fields TERMINATED by ','Optionally enclosed by '"'; --Table Data Import (note that the number of columns in the imported data corresponds to the columns of the table)--Delete Data First UseYouku;Delete  from User whereAge>Ten;Select *  from User;LOADDATA INFILE'F:/user.txt'  into TABLE User;Select *  from User; --Import tables with special formatting user1.txt (remove separator number ', ' and quotation marks of string "") UseYouku;Delete  from User whereAge>Ten;Select *  from User;LOADDATA INFILE'F:/user1.txt'  into TABLE UserFields TERMINATED by ','Optionally enclosed by '"'; Select *  from User;

=================

three txt file view
-- table Data Export SELECT *  from User     into ' F:/user.txt ';

Generate File User.txt

Admin Admin 18

Root root 18

Cat Cat 17

Dog Dog 15

Dog1 Dog1 15

Zhu Zhu 21

-- format the output as needed, each row of data ', ' delimited, and the string type data is enclosed in double quotes "" SELECT *  from User  into ' F:/user1.txt '  by ', ' by ' "'       ;

Generate File User1.txt

"Admin", "admin", 18

"Root", "root", 18

"Cat", "cat", 17

"Dog", "dog", 15

"Dog1", "Dog1", 15

"Zhu", "Zhu", 21

Conclusion: The specific import and export format of data you can try it yourself. However, personal advice involves formatting conversions, so try using other tools first, to prevent errors or to convert only plain text column data (no special formatting).

MySQL data table import and export

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.