into-outfile

Include headers when using SELECT INTO OUTFILE?

纵然是瞬间 提交于 2019-11-26 04:38:32
问题 Is it possible to include the headers somehow when using the MySQL INTO OUTFILE ? 回答1: You'd have to hard code those headers yourself. Something like: SELECT 'ColName1', 'ColName2', 'ColName3' UNION ALL SELECT ColName1, ColName2, ColName3 FROM YourTable INTO OUTFILE '/path/outfile' 回答2: The solution provided by Joe Steanelli works, but making a list of columns is inconvenient when dozens or hundreds of columns are involved. Here's how to get column list of table my_table in my_schema . --

How can I get around MySQL Errcode 13 with SELECT INTO OUTFILE?

烂漫一生 提交于 2019-11-26 04:30:39
问题 I am trying to dump the contents of a table to a csv file using a MySQL SELECT INTO OUTFILE statement. If I do: SELECT column1, column2 INTO OUTFILE \'outfile.csv\' FIELDS TERMINATED BY \',\' FROM table_name; outfile.csv will be created on the server in the same directory this database\'s files are stored in. However, when I change my query to: SELECT column1, column2 INTO OUTFILE \'/data/outfile.csv\' FIELDS TERMINATED BY \',\' FROM table_name; I get: ERROR 1 (HY000): Can\'t create/write to