Solved

Copy data from MySql table to a text file

Posted on 2009-06-29
3
427 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

734 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