如果我们从具有NULL值的表中导出数据,则MySQL会将\ N存储在CSV文件中,用于记录具有NULL值的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 | | 150 | Saurabh | NULL | Literature | +------+---------+------------+------------+ 7 rows in set (0.00 sec)
如我们所见,结果的id为150的address字段的结果为NULL。现在,以下查询将将该表的数据导出到Student_27.CSV-
mysql> Select * from Student_info INTO OUTFILE 'C:/mysql/bin/mysql-files/student_27.csv' FIELDS TERMINATED BY ',';
上面的查询在文件Student_27.CSV中存储了以下值-
101 YashPal Amritsar History 105 Gaurav Chandigarh Literature 125 Raman Shimla Computers 130 Ram Jhansi Computers 132 Shyam Chandigarh Economics 133 Mohan Delhi Computers 150 Saurabh \N Literature
我们可以看到MySQL将\ N存储在表具有NULL值的位置。