Load Data Into A Table
- Once a table is created, it needs to be populated with data.
- The
LOAD DATA and INSERT statements are useful for this.
- If starting with an empty table, an easy way to populate it is to create a text file containing a row for each record, then load the contents of the file into the table with a single statement.
- Create a text file containing one record per line, in the order in which the columns were listed in the
CREATE TABLE statement.
- Separate values by tabs.
- For missing values, use
\N to represent NULL values.
- Load the file with the
LOAD DATA statement.
- For example:
mysql> LOAD DATA LOCAL INFILE '/path/file.txt' INTO TABLE pet;
- To add new records one at a time, use the
INSERT statement:
- For example:
mysql> INSERT INTO pet
-> VALUES ('Puffball','Smith','hamster');
How do I retrieve information from a table?
© 2007 John Michael Pierobon
Notes