Q

Finding a utility to import fixed field data

MySQL expert Mike Hillyer explains how a user can import fixed field and delimited files using the LOAD FILE INFILE syntax of MySQL instead of using Microsoft Access.

I need to import fixed-field data into MySQL. I could use Microsoft Access to import it, then export it as a tab-delimited ASCII file to then be imported into MySQL. However, my IT shop is seeking an open source solution. Is there an open source utility that allows the importing of fixed-field (or column de-limited) data into MySQL?

MySQL can read fixed-width and de-limited files directly using the LOAD DATA INFILE command. The LOAD DATA INFILE command can be used to read data files located on either the server or the client (with the LOAD DATA LOCAL INFILE syntax), using any delimiters you specify or fixed-width.

The full syntax of LOAD DATA INFILE is available here. This is one example of reading a comma-delimited file:

LOAD DATA INFILE 'data.txt' INTO TABLE tbl_name
  FIELDS TERMINATED BY ',' ENCLOSED BY '"'
  LINES TERMINATED BY 'n';

LOAD DATA INFILE is generally quite fast. In my experience, I have seen it load three million rows in roughly ten seconds.

This was first published in May 2006

Dig deeper on Open source databases

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchDataCenter

SearchServerVirtualization

SearchCloudComputing

SearchEnterpriseDesktop

Close