
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can we export all the data from MySQL table into a text file?
It can be done with the help of SELECT … INTO OUTFILE statement. We are illustrating it with the help of the following example −
Example
Suppose we are having following data from table ‘Student_info’:
mysql> Select * from Student_info; +------+---------+------------+------------+ | id | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History | | 105 | Gaurav | Chandigarh | Literature | | 125 | Raman | Shimla | Computers | | 130 | Ram | Jhansi | Computers | | 132 | Shyam | Chandigarh | Economics | | 133 | Mohan | Delhi | Computers | +------+---------+------------+------------+ 6 rows in set (0.07 sec)
Now, the following query can export all the data from ‘Student_info’ table into a file named ‘student.txt’:
mysql> Select * from student_info INTO OUTFILE 'C:/mysql/bin/mysql-files/student.txt'; Query OK, 6 rows affected (0.01 sec)
The above query will create a file named ‘Student.txt’ and export all the data from ‘Student_info’ table into it.
- Related Articles
- How can we export all the data from MySQL table into a CSV file?
- How can we export some field(s) from MySQL table into a text file?
- How can we export some field(s) from MySQL table into a CSV file?
- How can we import data from .txt file into MySQL table?
- How can we import data from .CSV file into MySQL table?
- How can we import only specific columns from the text file, into MySQL table?
- How can we MySQL LOAD DATA INFILE statement with ‘ENCLOSED BY’ option to import data from text file into MySQL table?
- How can I export values based on some conditions from MySQL table into a file?
- How can we MySQL LOAD DATA INFILE statement with ‘FIELDS TERMINATED BY’ option to import data from text file into MySQL table?
- How can we import the text file, having data on the same line with a separator, into MySQL table?
- How can we import the text file, having some line prefixes, into MySQL table?
- How can we insert data into a MySQL table?
- What kind of settings can we do to a text file by query while exporting the values from MySQL table into a text file?
- How MySQL evaluates if we export the data to CSV file from a table which contains a NULL value(s)?
- How can we write MySQL stored procedure to select all the data from a table?

Advertisements