Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to add column name when export mysql data to a text fiel

Status
Not open for further replies.
Sep 21, 2004
108
US
I have been export data from MySQl by using the code below

select date, time into outfile 'c:/testexport.txt'from test1

The text file will have the data but has no names of the column. Is there a way that I can add a column name of the data in the exported text file here?

Thanks for help
 
you can use the technique of piping output to a file so with a dos prompt using the mysql client on windows

c:\>mysql -u yourusername -p -e "select date,time from mydatabase.test1" >myoutputfile.txt

The best way to get data out of mysql is dependent on where you want it to go some options are:

..Use ODBC and connect to mysql from another application OK upto relatively large volumes
..Use C Perl, PHP etc. etc. to access data if you want lots of control
..If you want quick but fast say >2m records then use select into outfile and I would recommend tab as a delimiter (which just gives you the data) and "show create table test1" which will dump the column definitions for you and with a little tweaking your can turn this into a create table statement for any other database
..Or just google for mysql2dbf mysql2excel mysql2csv mysql2.... there are lots of code snippets and applications around
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top