MySQL command line export, import Select query results

Source: Internet
Author: User

<!-- Environment: Windows 2003 SP2 + MySQL5.5.28    -

Sometimes you need to save the results that you query in one table with a SELECT statement to another table with the same structure, and you can do that with a pair of SQL statements at the command line:

Export Query Result: SELECT statement into outfile ' save path + filename ';

Import Query Result: Load data local infile ' save path + filename ' into table indicates character set UTF8;

For example:

Query the data in the table jc_archives in the database jc1992 that was published later than September 1, 2014, and save it in the Mysqltmp directory of local Disk D, save it as 1.sql, and enter it on the command line:

SELECT *  from where senddate>unix_timestamp ('2014-9-1'into' D://mysqltmp/1.sql ';

Results

1.sql Open With EditPlus

Then import the 1.sql of the saved query results into the table archives of DATA_TMP in the other database and enter it on the command line:

load data local infile "D:///mysqltmp/1intotablecharacter  set UTF8;

Results

This imports the query results from the first table into the second table. It is important to note that when importing, the values of the primary key or unique index of the two tables cannot be duplicated, otherwise they will skip no execution or report a warning:

MySQL command line export, import Select query results

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.