Mysql exports select results to files

Source: Internet
Author: User


Mysql-hxx-uxx-pxx-e "query statement" db> file example: mysql-h127.0.0.1-uroot-p000000-e "select * from a" test> 1.txt host ip user password query statement database filename: mysql-h127.0.0.1-uroot-p000000-N-e "select * from a" test> 1.txt host ip user password query statement database filename or mysql-hxxx-uxx-pxx select * from table into outfile 'xxx.txt '; for example: mysql-h127.0.0.1-uroot-p000000 select * from a into outfile '1.txt '; the two methods have the same effect. The second method is mysql documentation: SELECT [select options go here] INTO {OUTFILE | DUMPFILE} filename EXPORT_OPTIONS FROM table_references [additional select options go here] example: mysql-h127.0.0.1-uroot-p000000 select * from a into outfile "1.txt" fields terminated by '\ t' lines terminated by' \ r \ N': use mysql-e to execute the SQL statement mysql-hxx-uxx-pxx-e "query statement" db for Exported Files. For example: mysql-h127.0.0.1-uroot-p000000-e "select * from a into outfile '1.txt 'fields terminated ', 'Lines terminated by '\ r \ N' "test if you do not want to output column name information: mysql-h127.0.0.1-uroot-p000000-N-e "select * from a into outfile '1.txt 'fields terminated ', 'Lines terminated by '\ r \ N' "test by default, the files exported by mysql-e are separated by" \ t, rows are separated by "\ r \ n" (dos), and rows are separated by "\ n" (unix append method: select col002, col005, col004, col008 into outfile 'e:/mysql/i0812.txt 'fields terminated by' | 'Lines terminated by '\ r \ n' from a where col003 in (select col001 from qdbm) order by col005;
Author zhanghe086

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.