How does mysql export specified data or some data?

Source: Internet
Author: User

In this case, mysqldump may be difficult to solve. The following method can be used to solve this problem.

Method 1: Use insert and select in combination

1. Create a new table, such as new-table, containing the name of the field to be exported, such as a, B, and c.
2. Use insert into new-table (a, B, c) select a, B, c from old-table;
3. The remaining step is to export the new table and process the text.

Method 2: use MySQL's select into outfile backup Statement (recommended)

In the following example, a file is generated, and each value is separated by a comma. This format can be used by many programs.
Copy codeThe Code is as follows:
SELECT a, B, a + B INTO OUTFILE '/tmp/result. text'
Fields terminated by ', 'optionally enclosed '"'
Lines terminated by '\ N'
FROM test_table;

For details, see the usage of select.

Copy codeThe Code is as follows: select subject into outlifile '/tmp/xiaoruizi. text' fields terminated by '\ t' optionally enclosed by' "'Lines terminated by '\ n' from pw_blog;

Method 3: Use mysqldump

What's amazing is that I found that mysqldump actually has a very useful parameter "-w"

Instructions in the help document:
Copy codeThe Code is as follows:
-W |-where =
Dump only selected records; QUOTES mandatory!

Can this parameter be used to export some values? For example, if I want to export some data whose id is greater than 2312387:

Copy codeThe Code is as follows: mysqldump-u root-p bbscs6 BBSCS_USERINFO-where "ID> 2312387"> BBSCS_USERINFO-par. SQL

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.