MySQL query results export/output/write to File
Method One:
Execute the command directly:
Mysql> Select COUNT (1) fromtable into outfile '/tmp/test.xls ';
Query OK, Rows Affected (0.00 sec)
The file is generated under directory/tmp/Test.xls
Problems encountered:
Mysql>
Select COUNT (1) fromtable into outfile '/data/test.xls ';
Error:
ERROR 1 (HY000): Can ' t create/write to file '/data/test.xls ' (errcode:13)
Possible cause: MySQL does not have permission to write to/data/
Method Two:
The query is automatically written to the file:
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 are overwritten before and after
Mysql> select * FROM table;
$ rows in Set (0.59 sec)
Query results are no longer displayed at the box port
Method Three:
Jump out of MySQL command line
[Email protected] ~]#
mysql-h 127.0.0.1-u root-p xxxx-p 3306-e "select * from table" >/tmp/test/txt
MySQL query results output to file