Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 444
  • Last Modified:

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?
0
Cristi_E
Asked:
Cristi_E
  • 2
1 Solution
 
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
 
Raja Jegan RSQL 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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now