mysqldude

Import fixed width/row format

Version compatibility

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.8
FIELDS TERMINATED BY '' (fixed-row format, original)
original post
✓✓✗ 1406✗ 1406✗ 1406✗ 1406✗ 1406✗ 1406✗ 1406
Read each line into a variable and cut with SUBSTRING (any column types)
modern rewrite
✓✓✓✓✓✓✓✓✓
Fixed-row format into an INT column
version check
✓✓✗ 1406✗ 1406✗ 1406✗ 1406✗ 1406✗ 1406✗ 1406
Fixed-row format into a latin1 table (single-byte charset)
version check
✓✓✓✓✓✓✓✓✓
Fixed-row format with LOAD DATA ... CHARACTER SET latin1 (utf8mb4 table)
version check
✓✓✗ 1406✗ 1406✗ 1406✗ 1406✗ 1406✗ 1406✗ 1406
FIELDS TERMINATED BY '' (fixed-row format, original) original post
MySQL 5.6✓5.7✓8.0✗ 14068.4✗ 14069✗ 1406
MariaDB 10.6✗ 140610.11✗ 140611.4✗ 140611.8✗ 1406
Read each line into a variable and cut with SUBSTRING (any column types) modern rewrite
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
Fixed-row format into an INT column version check
MySQL 5.6✓5.7✓8.0✗ 14068.4✗ 14069✗ 1406
MariaDB 10.6✗ 140610.11✗ 140611.4✗ 140611.8✗ 1406
Fixed-row format into a latin1 table (single-byte charset) version check
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
Fixed-row format with LOAD DATA ... CHARACTER SET latin1 (utf8mb4 table) version check
MySQL 5.6✓5.7✓8.0✗ 14068.4✗ 14069✗ 1406
MariaDB 10.6✗ 140610.11✗ 140611.4✗ 140611.8✗ 1406
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-25 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9
What the warnings and failures say (3)
  • FIELDS TERMINATED BY '' (fixed-row format, original) (MySQL 8.0, MySQL 8.4, MySQL 9, MariaDB 10.6, MariaDB 10.11, MariaDB 11.4, MariaDB 11.8): error 1406: Data too long for column 'name' at row 1
  • Fixed-row format into an INT column (MySQL 8.0, MySQL 8.4, MySQL 9, MariaDB 10.6, MariaDB 10.11, MariaDB 11.4, MariaDB 11.8): error 1406: Data too long for column 'name' at row 1
  • Fixed-row format with LOAD DATA ... CHARACTER SET latin1 (utf8mb4 table) (MySQL 8.0, MySQL 8.4, MySQL 9, MariaDB 10.6, MariaDB 10.11, MariaDB 11.4, MariaDB 11.8): error 1406: Data too long for column 'name' at row 1

The original article

First published 2012-05-24. The text below is the original; the table above shows how it behaves on current versions.

Imagine you have a file that contains data in fixed row format. By that I mean that on a single row, column 1-10 contains one field, 11-15 another field etc. and this file needs to be uploaded into your MySQL database. How can this be achieved in MySQL.

The LOAD DATA INFILE command allows fixed format to be uploaded. However, there is one caveat with this and that is the content uploaded must be all CHAR or VARCHAR. The LOAD DATA INFILE will use the field dimensions to determine the length of each field.

Consider the following:

CREATE TABLE testimport (
	name VARCHAR(10),
	age VARCHAR(2)
);

And with this we want to import the following file:

TOM        3
DICK       7
HARRY     14

Then we need to issue the command and using the “FIELDS TERMINATED BY ”” clause.

mysql> load data infile '/home/rcashell/mysql/fixed/testimport.txt' into table testimport fields terminated by '';
Query OK, 3 rows affected (0.01 sec)
Records: 3  Deleted: 0  Skipped: 0  Warnings: 0

mysql> select * from testimport;
+------------+------+
| name       | age  |
+------------+------+
| TOM        |  3   |
| DICK       |  7   |
| HARRY      | 14   |
+------------+------+
3 rows in set (0.00 sec)