title: MySQL load NULL values from CSV data
body: <p>I have a file that can contain from 3 to 4 columns of numerical values which are separated by comma. Empty fields are defined with the exception when they are at the end of the row:</p>
  
  <pre><code>1,2,3,4,5
  1,2,3,,5
  1,2,3
  </code></pre>
  
  <p>The following table was created in MySQL:</p>
  
  <pre>
  +-------+--------+------+-----+---------+-------+
  | Field | Type   | Null | Key | Default | Extra |
  +-------+--------+------+-----+---------+-------+
  | one   | int(1) | YES  |     | NULL    |       | 
  | two   | int(1) | YES  |     | NULL    |       | 
  | three | int(1) | YES  |     | NULL    |       | 
  | four  | int(1) | YES  |     | NULL    |       | 
  | five  | int(1) | YES  |     | NULL    |       | 
  +-------+--------+------+-----+---------+-------+
  </pre>
  
  <p>I am trying to load the data using MySQL LOAD command:</p>
  
  <pre><code>LOAD DATA INFILE '/tmp/testdata.txt' INTO TABLE moo FIELDS 
  TERMINATED BY "," LINES TERMINATED BY "\n";
  </code></pre>
  
  <p>The resulting table:</p>
  
  <pre>
  +------+------+-------+------+------+
  | one  | two  | three | four | five |
  +------+------+-------+------+------+
  |    1 |    2 |     3 |    4 |    5 | 
  |    1 |    2 |     3 |    0 |    5 | 
  |    1 |    2 |     3 | NULL | NULL | 
  +------+------+-------+------+------+
  </pre>
  
  <p>The problem lies with the fact that when a field is empty in the raw data and is not defined, MySQL for some reason does not use the columns default value (which is NULL) and uses zero. NULL is used correctly when the field is missing alltogether.</p>
  
  <p>Unfortunately, I have to be able to distinguish between NULL and 0 at this stage so any help would be appreciated.</p>
  
  <p>Thanks
  S.</p>
  
  <p>edit</p>
  
  <p>The output of SHOW WARNINGS:</p>
  
  <pre>
  +---------+------+--------------------------------------------------------+
  | Level   | Code | Message                                                |
  +---------+------+--------------------------------------------------------+
  | Warning | 1366 | Incorrect integer value: '' for column 'four' at row 2 | 
  | Warning | 1261 | Row 3 doesn't contain data for all columns             | 
  | Warning | 1261 | Row 3 doesn't contain data for all columns             | 
  +---------+------+--------------------------------------------------------+
  </pre>