Solved

Copy data from MySql table to a text file

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS SQL Update query with connected table data 3 41
help restore my wordpress site made on WAMP 8 29
Link failure 16 35
Wordpress Only run code if on a certain page 11 23
Read about achieving the basic levels of HRIS security in the workplace.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 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