Mysql 如何使用表格选项以 csv 格式导出文件?
Mysql How to outfile in csv format, with sheets options?
我想将数据从 mysql 导出到 csv。有很多表,所以我想要一个包含很多表的 csv 文件。怎么做到的?
我想是这样的:
SELECT *
FROM product
WHERE active = 1
INTO OUTFILE '/root/tmp/data.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
SELECT *
FROM member
WHERE active = 1
INTO OUTFILE '/root/tmp/data.csv' // using the same .csv
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
etc...
您不能使用 INTO OUTFILE
追加到现有文件。
https://dev.mysql.com/doc/refman/5.7/en/select-into.html 说:
file_name cannot be an existing file, which among other things prevents files such as /etc/passwd
and database tables from being destroyed.
因此您必须将每个 table 输出到不同的文件,然后自己将它们连接在一起(即不使用 SQL)。
我想将数据从 mysql 导出到 csv。有很多表,所以我想要一个包含很多表的 csv 文件。怎么做到的?
我想是这样的:
SELECT *
FROM product
WHERE active = 1
INTO OUTFILE '/root/tmp/data.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
SELECT *
FROM member
WHERE active = 1
INTO OUTFILE '/root/tmp/data.csv' // using the same .csv
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n';
etc...
您不能使用 INTO OUTFILE
追加到现有文件。
https://dev.mysql.com/doc/refman/5.7/en/select-into.html 说:
file_name cannot be an existing file, which among other things prevents files such as
/etc/passwd
and database tables from being destroyed.
因此您必须将每个 table 输出到不同的文件,然后自己将它们连接在一起(即不使用 SQL)。