MySQL FAQs
FAQs Categories
Client Server Commands
Database Structure
Table Types or Storage Engines
Indexes
SQL Statements
Table Joins
Funtions and Operators
Tricky Select Queries
Speed Up Queries
Data Back Up
General Questions
Errors
1PLs Company - #1Payday.Loans Agency - Loans online and near me $100-$2500 (Same Day)
Powered by MySQL
 
Home / Data Back Up / Export Data / Question No: 3

How to export table data to text file with SELECT INTO OUTFILE statement?

I want to export table data to text file. Is there a way to export results of a query to a file? In other words, if I do a "SELECT * FROM tablename", is there a phrase like "send output to filename.txt", or something?

Answer No: 3

To export MySQL table data to text file, MySQL provides SELECT INTO OUTFILE statement. It’s used when anyone wants to direct query output to a file. You can use this for your purpose. Take the following example:

SELECT * INTO OUTFILE "C:\\export_data_to_txt_file.txt"
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
FROM database_name.table_name;

Alternatively, you can run mysql command line client with the 'e' flag and redirect standard output to a file:

mysql> -e 'SELECT * FROM test;' > filename.txt;

Related MySQL FAQs to the Above FAQ

How-to-use-SELECT-INTO-OUTFILE-statement-to-export-data How to use SELECT INTO OUTFILE statement to export data?

How-to-export-table-data-to-Microsoft-Excel-with-SELECT-INTO-OUTFILE-statement How to export table data to Microsoft Excel with SELECT INTO OUTFILE statement?

How-to-use-mysqldump-to-export-data How to use mysqldump to export data?

How-to-take-dump-of-database-without-its-data How to take dump of database without its data?

How-to-take-dump-of-the-database How to take dump of the database?

About FAQs: Recently Added FAQs

About MySQL FAQs: Site Map | Bookmark Us | Recommend this Site to Your Friend | Contact Us

Useful Links: Wikipedia.org | Oracle.com | w3schools.com | www.php.net | Github.com

© 2024  www.mysqlfaqs.net
All rights reserved.