Mysql Export a method that specifies data or partial data _mysql

Source: Internet
Author: User

This time mysqldump may not be very good, use the following method can solve this problem.

Method One, insert, and select in conjunction with

1, create a new table, such as New-table, contains the name of the field to be exported, such as A,b,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 then the text processing

Method Two, use the MySQL SELECT INTO OutFile Backup statement (recommended)

In the following example, a file is generated with the values separated by commas. This format can be used by many programs.

Copy Code code as follows:

SELECT a,b,a+b into outfile '/tmp/result.text '
FIELDS terminated by ', ' optionally enclosed by ' '
LINES terminated by ' \ n '
From Test_table;

See details of how select is used

Copy Code code as follows:
Select subject into Outlifile '/tmp/xiaoruizi.text ' fields terminated by ' \ t ' optionally enclosed by ' "' lines terminated By ' \ n ' from Pw_blog;

Method Iii. use of mysqldump

It's amazing that I found out that mysqldump actually had a very good parameter, "-W."

Instructions on the Help document:

Copy Code code as follows:

-w|–where=
Dump only selected records; Quotes mandatory!

So is it possible to use this parameter to derive some values? For example, I just need to export some data with ID greater than 2312387:

Copy Code code as follows:
Mysqldump-u root-p bbscs6 bbscs_userinfo–where "id>2312387" > Bbscs_userinfo-par.sql

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.