Mysql query result output to the file method, mysql Query Result

Source: Internet
Author: User

Mysql query result output to the file method, mysql Query Result

Export/output/Write mysql query results to a file

Method 1:

Run the following command:
Mysql> select count (1) from table into outfile '/tmp/test.xls ';

Query OK, 31 rows affected (0.00 sec)
Upload the file test.xls under/tmp /.

Problems:
Mysql> select count (1) from table into outfile '/data/test.xls ';

Error:
ERROR 1 (HY000): Can't create/write to file '/data/test.xls' (Errcode: 13)

Possible cause: mysql has no permission to write data to/data /.

Method 2:

All queries are automatically written to files:
Mysql> pager cat>/tmp/test.txt;
PAGER set to 'cat>/tmp/test.txt'
All subsequent query results are automatically written to/tmp/test.txt 'and overwritten
Mysql> select * from table;
30 rows in set (0.59 sec)
No query results are displayed in the box

Method 3:

Jump out of mysql Command Line
[Root @ SHNHDX63-146 ~] # Mysql-h 127.0.0.1-u root-p XXXX-P 3306-e "select * from table">/tmp/test/txt

The above is all the methods for outputting mysql query results to files provided by xiaobian. I hope you can provide more support ~

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.