Training, Open Source computer languages

This is page http://www.wellho.net/forum/The-MySQ ... abase/Loading-a-table-from-data-in-a-text-file.html

Our email: info@wellho.net • Phone: 01144 1225 708225

 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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.

Quote:
# 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/wood.xyz" 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..

HTH

Posted by admin (Graham Ellis), 11 October 2003
You can say
      LOAD DATA LOCAL INFILE
rather than
      LOAD DATA INFILE
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 www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho