Export and Import csv file code in mysql command mode

Source: Internet
Author: User
We can use the mysql command mode to import or export csv files. If you need it, you can simply refer to it.

We can use the mysql command mode to import or export csv files. If you need it, you can simply refer to it.

> * From tt_address;
+ ----- + -------- + ------ + -------- + ------------ + ------------- + ------
----- + ---------- + ------- + ---------------------- + ------- + -------- + ----- + -------
-- + ---------- + ------ + --------- + ------ + ----- + -------- + --------- + ------- + ----- + ---
------ + ------------- + -------------- + --------------------------- + ----------------
------- +
| Uid | pid | tstamp | hidden | name | gender | first_name | middle_name | last _
Name | birthday | title | email | phone | mobile | www | addres
S | building | room | company | city | zip | region | country | image | fax | de
Leted | description | addressgroup | module_sys_dmail_category | module_sys_dmai
Rochelle HTML |
+ ----- + -------- + ------ + -------- + ------------ + ------------- + ------
----- + ---------- + ------- + ---------------------- + ------- + -------- + ----- + -------
-- + ---------- + ------ + --------- + ------ + ----- + -------- + --------- + ------- + ----- + ---
------ + ------------- + -------------- + --------------------------- + ----------------
------- +
| 2 | 42 | 0 | 1 | m | aa
| 0 | tian.li@atop-online.de |
| D |
0 | 0 | 0 |
0 |
+ ----- + -------- + ------ + -------- + ------------ + ------------- + ------
----- + ---------- + ------- + ---------------------- + ------- + -------- + ----- + -------
-- + ---------- + ------ + --------- + ------ + ----- + -------- + --------- + ------- + ----- + ---
------ + ------------- + -------------- + --------------------------- + ----------------
------- +
1 row in set (0.00 sec)
There is only one piece of data in this table. Now, the exported csv file only needs uid, name, gender, email, and module_sys_dmail_html. the command line is as follows: select uid, name, gender, email, module_sys_dmail_html into outfile 'd: \ test7.csv 'fields terminated ', 'optionally enclosed by '"'Lines terminated by 'n' from tt_address
Run the following command to import a cvs file to MySql:
Mysql> load data local infile 'e: \ input1.csv 'into table test1 fields terminated by', 'Lines terminated by 'n' (first_name, last_name, email );

Fields terminated by ---- field Terminator
Fields optionally enclosed by ---- envelope character
Lines terminated by ---- line terminator

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.