11

I'm having problem using xampp (4.1.6) phpmyadmin export function. When I export, I select csv for excel format, but it will return the data like:

1;"data1";"0";"6828";"2014-03-13 13:54:26";"2014-03-13 13:54:26";"file";;"2014-03-14 14:45:51"

So I tried the syntax:

SELECT * FROM `directory_listing` 
INTO OUTFILE 'C:/test.csv' 
FIELDS TERMINATED BY ',' 
ENCLOSED BY '"' 
LINES TERMINATED BY '\n'

Now the format is the same as the table view as in mysql table. Problem is, I want to display the column name on 1st row. How can i do that?

By the way, below is the interface of my phpmyadmin export function.

phpmyadmin export tab

I tried to export it as normal csv, but it still return the same. even worse, ALL the data is put inside 1st row.

phpmyadmin export for normal csv

5
  • “but it will return the data like […]” – and how exactly does that differ from the result you want?
    – CBroe
    Mar 14, 2014 at 8:52
  • hi, when I execute the syntax [SELECT * FROM directory_listing INTO OUTFILE 'C:/test.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'], it creates a file name test.csv in my C:\, when I open it (ms.excel), the format is exactly like the mysql table without the column header Mar 14, 2014 at 10:28
  • And that is exactly why one would normally use the export functionality of pma, and check the box “Put column names in first row”. Why that is not enough for you, is still unclear.
    – CBroe
    Mar 14, 2014 at 10:53
  • hi, when I try to use the built-in functionality, the data exported is like this:(1;"data1";"0";"6828";"2014-03-13 13:54:26";"2014-03-13 13:54:26";"file";;"2014-03-14 14:45:51")=>all in one cell. Mar 14, 2014 at 12:22
  • That is not “all in one cell” at all – only Excel has the annoying habit of not recognizing the format correctly if you open such a file via double click. Try the “open” dialog from within Excel … then it’ll present you with a second dialog where you can specify which field delimiters are used in the file.
    – CBroe
    Mar 14, 2014 at 12:41

2 Answers 2

4

You almost got it right, you just have to check the "Put colums names in first row" checkbox and then start the export. That should do the job.

EDIT::

Since your doin it your self you can get the fieldnames with this MYSQL query:

    SELECT `COLUMN_NAME` 
FROM `INFORMATION_SCHEMA`.`COLUMNS` 
WHERE `TABLE_SCHEMA`='yourdatabasename' 
    AND `TABLE_NAME`='yourtablename';
4
  • hi. i'm not using the built-in export function from phpmyadmin. instead I type the syntax myself to produce the format I want, it's just that I don't know how to add the column header... Mar 14, 2014 at 8:30
  • hi, what I want is to export the table data together with the contents into readable csv for excel. the syntax I run (as on 1st post) did export the db data, but without the header. What I need to include the header(column name)... Mar 14, 2014 at 10:29
  • @ThatMSG In INTO OUTFILE 'C:/test.csv' does this test.csv automatically gets created or shoud we have created a blank spreadsheet with the name test.csv for the data to be exported to
    – sam_rox
    May 24, 2015 at 14:29
  • If mysql/apache or what have you are using to export the data has the right to write to the selected directory, then the file will be created automatically
    – ThatMSG
    May 24, 2015 at 18:43
0

Just check the Put columns names in the first row checkbox above the Go button.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.