faqts : Computers : Databases : MySQL : Common Problems : Importing Data

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

19 of 51 people (37%) answered Yes
Recently 3 of 10 people (30%) answered Yes

Entry

How can I import data with fixed size fields into MySQL?
Is it possible to import fixed size data directly into MySQL tables?
How get I get data from another dabase server?

May 13th, 2000 02:04
Nathan Wallace, Rene Perez, Dan Nelson, Tim Smith


Sure it will - here's a manual snippet:

   * If the `FIELDS TERMINATED BY' and `FIELDS ENCLOSED BY' values are
     both empty (`'''), a fixed-row (non-delimited) format is used. 
     With fixed-row format, no delimiters are used between fields. 
     Instead, column values are written and read using the "display"
     widths of the columns.  For example, if a column is declared as
     `INT(7)', values for the column are written using 7-character
     fields.  On input, values for the column are obtained by reading 7
     characters.  Fixed-row format also affects handling of `NULL'
     values; see below.  Note that fixed size format will not work if
     you are using a multi-byte character set.

So you just have to make sure that the field widths in your datafile
and your table match.

You could also try morphing the data into a tab delimited format with
perl and then importing it.  For example:

   perl -lne 'print join("\t", map {s,\\,\\\\,g; s,\t,\\\t,g; $_} unpack
"a13a21a2", $_), "\n"'

This assumes you have three columns of 13, 21 and 2 characters
each (change the "a13a21a2" as appropriate for your file).

Then just load the resulting file into MySQL - no extra aguments
needed.