Copy data from MySql table to a text file

Hello!
   How can i copy data from MySql table to a text file using SQL commands?
LVL 4
Cristi_EAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Raja Jegan RConnect With a Mentor SQL Server DBA & ArchitectCommented:
Suppose you have to create a CSV file from your table containing columns a and b and your table is named test_table, then this should help you out

SELECT a,b,a+b INTO OUTFILE 'C:\test\result.txt'
  FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
  LINES TERMINATED BY '\n'
  FROM test_table;

The above code will create a CSV file with Strings enclosed with "" in the file path you specify.

If you need to have any other formatting for the output file, Kindly specify so that I can help you out.
0
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
This should help you out:

SELECT ... INTO OUTFILE 'file_name'

Kindly refer below for more options and references:

http://dev.mysql.com/doc/refman/5.0/en/select.html
0
 
Cristi_EAuthor Commented:
Can you help me with some sample code?    I'm not too fammiliar with SQL.

Thanks in advance!
0
All Courses

From novice to tech pro — start learning today.