可以借助SELECT…INTO OUTFILE语句来完成。我们将在以下示例的帮助下进行说明-
假设我们从表“ Student_info”中获得以下数据:
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)
现在,以下查询可以将“ Student_info”表中的所有数据导出到名为“ student.txt”的文件中:
Select * from student_info INTO OUTFILE 'C:/mysql/bin/mysql-files/student.txt';
上面的查询将创建一个名为“ Student.txt”的文件,并将“ Student_info”表中的所有数据导出到该文件中。