Is it possible to include the headers somehow when using the MySQL INTO OUTFILE
?
相关问题
- sqlyog export query result as csv
- NOT DISTINCT query in mySQL
- MySQL: conduct a basic search
- Why sometimes there is one of more gap(s) in the v
- mySQL alter table on update, current timestamp
This will alow you to have ordered columns and/or a limit
I would like to add to the answer provided by Sangam Belose. Here's his code:
However, if you have not set up your
"secure_file_priv"
within the variables, it may not work. For that, check the folder set on that variable by:The output should look like this:
You can either change this variable or change the query to output the file to the default path showing.
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.
Now you can copy & paste the resulting row as first statement in Joe's method.
Actually you can make it work even with an ORDER BY.
Just needs some trickery in the order by statement - we use a case statement and replace the header value with some other value that is guaranteed to sort first in the list (obviously this is dependant on the type of field and whether you are sorting ASC or DESC)
Let's say you have three fields, name (varchar), is_active (bool), date_something_happens (date), and you want to sort the second two descending: