O'Reilly logo

Sams Teach Yourself MySQL by Chris Newman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Loading Data from a File

You can load data from an external file into MySQL using the LOAD DATA INFILE command. The data in your file must be in a structured format—the default format is one record on each line, with values separated by tabs.

The file shown in Listing 15.1 contains a file that could be loaded into the products table using the following command:

LOAD DATA INFILE '/home/chris/listing15.1.txt'
INTO TABLE products;
Listing 15.1. Sample Tab-Separated Data File
BLUE    Blue product    3.0     13.99
RED     Red product     3.5     25.00
GREEN   Green product   4.5     6.50

Paths

If no path is given for the filename in LOAD DATA INFILE, MySQL looks for it in ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required