我正在使用phpmyadmin版本5.6.33。通过引用
准备查询以下载表http://www.mysqltutorial.org/mysql-export-table-to-csv/
(SELECT 'Order Number','Order Date','Status')
UNION
(SELECT orderNumber,orderDate, status
FROM orders
INTO OUTFILE 'C:/tmp/orders.csv'
FIELDS ENCLOSED BY '"' TERMINATED BY ';' ESCAPED BY '"'
LINES TERMINATED BY '\r\n');
我收到错误
Unrecognized Keyword FIELDS
Unrecognized Keyword ENCLOSED and so on...
参考某些链接
phpMyAdmin SQL Error Unrecognized keyword near FIELDS
Unrecognized key word Near Fields, Terminated When Using INTO OUTFILE in mysql query
但它对我没用。
答案 0 :(得分:0)
您需要将union作为子查询放入select into outfile的from子句中,因为您要导出整个redultset:
SELECT *
INTO OUTFILE 'C:/tmp/orders.csv'
FIELDS ENCLOSED BY '"' TERMINATED BY ';' ESCAPED BY '"'
LINES TERMINATED BY '\r\n'
FROM
((SELECT 'Order Number','Order Date','Status')
UNION
(SELECT orderNumber,orderDate, status
FROM orders));
答案 1 :(得分:0)
只需扩展Shadows的答案,我发现以下内容适用于phpmyadmin的SQL编辑器,如果......
#1248 - 每个派生表都必须有自己的别名
要避免警告消息secure_file_priv =" c:/ wamp64 / tmp"
注意:您需要在查询中更改此内容以适合您的使用情况。
其他报道:
#1290 - MySQL服务器正在运行--secure-file-priv选项,因此无法执行此语句
SELECT *
INTO OUTFILE 'C:/wamp64/tmp/orders.csv'
FIELDS ENCLOSED BY '"' TERMINATED BY ';' ESCAPED BY '"'
LINES TERMINATED BY '\r\n'
FROM
((SELECT 'Order Number','Order Date','Status')
UNION
(SELECT orderNumber,orderDate, status
FROM orders)) as orders_alias;
这就产生了csv文件。所以看看是否有帮助。