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 ...

Get Sams Teach Yourself MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.