Search code examples
mysqlimportload-data-infile

I can't load a MySQL table containing only integer columns from a file


I'm trying to import data to a MySQL table.

The table :

CREATE TABLE `MYTABLE` (
  `F1` bigint(20) NOT NULL,
  `F2` bigint(20) NOT NULL,
  `F3` int(11) NOT NULL,
  `F4` bigint(20) DEFAULT NULL,
  `F5` tinyint(4) NOT NULL,
  `F6` bigint(20) NOT NULL,
  `F7` bigint(20) NOT NULL,
  PRIMARY KEY (`F1`)
) ENGINE=InnoDB default charset=latin1;

The data file contains records of this form, which are separated by tab:

229733561174    44224449355443  0   0   0   55555557555000  12345678901

The import command :

mysql> load data infile 'try.txt' INTO TABLE MYTABLE;

The warnings I get:

Level Code Message
Warning 1366 Incorrect integer value: '229733561174' for column 'F1' at row 1
Warning 1366 Incorrect integer value: '44224449355443' for column 'F2' at row 1
Warning 1366 Incorrect integer value: '0 0 0 55555557555000 12345678901' for column 'F3' at row 1
Warning 1261 Row 1 doesn't contain data for all columns
Warning 1261 Row 1 doesn't contain data for all columns
Warning 1261 Row 1 doesn't contain data for all columns
Warning 1261 Row 1 doesn't contain data for all columns
7 rows in set (0.00 sec)

I can't figure out why the values of the first two columns are Incorrect integer value and why the values of columns 3-7 are all treated as a single column.

I tried changing the field separator to ',' (specifying it in the load data command), and still got the same warnings.

The output table contains 0s in all columns (except for the optional column that gets NULL).

Can someone please tell me what I'm doing wrong?


Solution

  • I found the problem. The default character set in my DB was ucs2, which caused the problem. If I specify a different character set in the load data infile command, everything works:

    load data infile 'try.txt' ignore 
    into table MYTABLE
    character set latin1
    fields terminated by '\t' enclosed by '' escaped by '\\'
    lines terminated by '\n' starting by ''
    ignore 1 lines;