Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
Python, Lua and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Java, C, C++, Ruby, MySQL and Linux / Tomcat systems
Loading a table from data in a text file

Posted by admin (Graham Ellis), 11 October 2003
I'm often asked how to load data in a text file into a table.   It can be done with load data infile, which has flexibility to handle different field and line delimiters, and can even handle fields that might or might not be encased in quotes.    Here's an example that includes a load data infile using a number of the options.

# Example of creating a database and table within it, and then loading
# the table from a "comma separated variable" file.

# Some sample lines from our data file:

# Douglas Fir,"N America, UK","light, reddish brown",530,3,y,"plywood, construction,joinery,vats"
# "Hemlock, Western",N America,pale brown,500,4,n,"construction, joinery"

drop database if exists sawmill;
create database sawmill;
use sawmill;

create table timbers (
       type    text,
       origin  text,
       colour  text,
       density int,
       hard    tinyint,
       sched   enum ("y","n"),
       useage  text,
       tid     int primary key auto_increment not null);

load data infile "/Library/Webserver/live_html/data/" into table timbers
       fields terminated by "," optionally enclosed by '"'
       (type, origin, colour, density, hard, sched, useage);

Posted by Custard (Custard), 11 October 2003
As an addendum, that may be 'deprecated' now,
last time I wanted to do this (on a solaris machine)
I had to run the mysql program with..

mysql -uUser -p --local-infile=1

... or it wouldn't work. Something to do with security afaicr.

I noted we didn't have to do it on the course, but we were using windows..


Posted by admin (Graham Ellis), 11 October 2003
You can say
rather than
and this will cause the data to be loaded from the client's disc rather than the server's disc.  The --local-infile option enables / disables the LOAD DATA LOCAL INFILE capability - in other words, it controls whether or not you can load data from the client's disc.  I don't think it effects the regular LOAD DATA INFILE command which loads data from the server's discs.

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2018: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01225 708225 • FAX: 01225 793803 • EMAIL: • WEB: • SKYPE: wellho