可以通过在SELECT…INTO OUTFILE语句中提供列名称来完成,同时将数据从MySQL表导出到文件中。我们将在以下示例的帮助下进行说明-
假设我们从表'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)
假设我们只希望将上表中的两列“ id”和“ Name”导出到文件中,那么以下查询可以将“ Student_info”表中的“ id”和“ name”值仅导出到名为“ student1.txt'-
mysql> Select id, Name from Student_info INTO OUTFILE 'C:/mysql/bin/mysql-files/student1.txt';
上面的查询将创建一个名为“ Student.txt”的文件,并将“ Student_info”表中的“ id”和“ name”列的值导出到其中。