MySQL saves query results as SQL files or txt files

Source: Internet
Author: User

1. New query statement file Query.sql, as follows:

The code is as follows Copy Code

Use appdb;
Set names UTF8;
Select Feedid, city, message from Feed limit 1000;


The above set names UTF8 statement is the encoding that the facility is currently using, and if the encoding is inconsistent with the database encoding, there will be garbled

2. Implementation is as follows:

The code is as follows Copy Code
[Root@proxy tianqg]# mysql-uroot-p < query.sql > Query.txt

Enter the password and create the query result file in the current directory Query.txt

TXT file generated above if you want to save as a. sql file we can do the following

The query results can be saved to a writable directory on the server side using the SELECT INTO outfile command:

The code is as follows Copy Code


Mysql> SELECT * from article limit to outfile '/test/article.sql ';

Query OK, affected (0.01 sec)

The Article.sql file is then downloaded to the local computer and the query result file is imported through the load data native infile into Table command:

The code is as follows Copy Code


Load data local infile "d:/study/article.sql" into table cmstop_article;

Affected rows: 150
Time: 0.722ms

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.