- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Advertisements