Solved

Copy data from MySql table to a text file

Posted on 2009-06-29
3
418 Views
Last Modified: 2013-12-13
Hello!
   How can i copy data from MySql table to a text file using SQL commands?
0
Comment
Question by:Cristi_E
  • 2
3 Comments
 
LVL 57

Expert Comment

by:Raja Jegan R
ID: 24735567
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
 
LVL 4

Author Comment

by:Cristi_E
ID: 24735591
Can you help me with some sample code?    I'm not too fammiliar with SQL.

Thanks in advance!
0
 
LVL 57

Accepted Solution

by:
Raja Jegan R earned 500 total points
ID: 24735623
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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now