Solved

Copy data from MySql table to a text file

Posted on 2009-06-29
3
431 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

636 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