创造测试数据
mysql> create table test(a int,b char(4),c int);
Query OK, 0 rows affected (0.09 sec)
mysql> select * from test;
+------+------+------+
| a | b | c |
+------+------+------+
| 1 | NULL | 1 |
| 1 | a | NULL |
| 1 | | 1 |
| NULL | NULL | NULL |
+------+------+------+
4 rows in set (0.00 sec)
将数据写入到文件中
mysql> select * from test into outfile '/tmp/test.txt' fields terminated by ',' enclosed by '"' lines terminated by '\r\n';
Query OK, 4 rows affected (0.00 sec)
[root@lzl tmp]# cat test.txt
"1",\N,"1"
"1","a",\N
"1","","1"
[root@lzl tmp]# cat test.txt
"1",\N,"1"
"1","a",\N
"1","","1"
\N,"NULL",\N
测试导入
mysql> create table testa like test;
Query OK, 0 rows affected (0.04 sec)
load data infile '/tmp/test.txt' into table testa fields terminated by ',' enclosed by '"' lines terminated by '\r\n';
mysql> select * from testa;
+------+------+------+
| a | b | c |
+------+------+------+
| 1 | NULL | 1 |
| 1 | a | NULL |
| 1 | | 1 |
| NULL | NULL | NULL |
+------+------+------+
4 rows in set (0.00 sec)
mysql> select * from testa where b='NULL';
+------+------+------+
| a | b | c |
+------+------+------+
| NULL | NULL | NULL |
+------+------+------+
1 row in set (0.01 sec)
mysql> select * from testa where a='NULL';
Empty set, 1 warning (0.00 sec)
mysql> select * from testa where a is NULL;
+------+------+------+
| a | b | c |
+------+------+------+
| NULL | NULL | NULL |
+------+------+------+
1 row in set (0.04 sec)
4 rows in set (0.00 sec)
总结:
1 null值into outfile后格式是\N,load可以正常导入null值
2 null字符串可以正常识别
3 oceanbase测试导出null值后,文件中显示的是NULL,load导入NULL字符串。被oceanbase玩死