Oracle 5.0 Reference Manual page 1094

Table of Contents

Advertisement

LOAD DATA INFILE 'data.txt' INTO TABLE db2.my_table;
For security reasons, when reading text files located on the server, the files must either reside in the
database directory or be readable by all. Also, to use
have the
[577]
privilege. See
FILE
operations, if the
secure_file_priv
file to be loaded must be located in that directory.
Using
is a bit slower than letting the server access the files directly, because the contents of the
LOCAL
file must be sent over the connection by the client to the server. On the other hand, you do not need
the
[577]
privilege to load local files.
FILE
also affects error handling:
LOCAL
• With
INFILE, data-interpretation and duplicate-key errors terminate the operation.
LOAD DATA
• With
LOAD DATA LOCAL
and the operation continues because the server has no way to stop transmission of the file in the
middle of the operation. For duplicate-key errors, this is the same as if
is explained further later in this section.
The
and
REPLACE
IGNORE
unique key values:
• If you specify REPLACE, input rows replace existing rows. In other words, rows that have the same
value for a primary key or unique index as an existing row. See
• If you specify IGNORE, input rows that duplicate an existing row on a unique key value are skipped.
• If you do not specify either option, the behavior depends on whether the
Without LOCAL, an error occurs when a duplicate key value is found, and the rest of the text file is
ignored. With LOCAL, the default behavior is the same as if
server has no way to stop transmission of the file in the middle of the operation.
To ignore foreign key constraints during the load operation, issue a
statement before executing
If you use
LOAD DATA INFILE
separate batch (as for
you have many indexes. In some extreme cases, you can create the indexes even faster by turning
them off with
ALTER TABLE ... DISABLE KEYS
ALTER TABLE ... ENABLE KEYS
"Speed of
Statements".
INSERT
For both the
LOAD DATA INFILE
and
clauses is the same. Both clauses are optional, but
FIELDS
LINES
if both are specified.
If you specify a
FIELDS
BY, and
BY) is also optional, except that you must specify at least one of them.
ESCAPED
If you specify no
FIELDS
FIELDS TERMINATED BY '\t' ENCLOSED BY '' ESCAPED BY '\\'
LINES TERMINATED BY '\n' STARTING BY ''
(Backslash is the MySQL escape character within strings in SQL statements, so to specify a literal
backslash, you must specify two backslashes for the value to be interpreted as a single backslash. The
escape sequences
'\t'
In other words, the defaults cause
LOAD DATA INFILE
Section 6.2.1, "Privileges Provided by
[490]
INFILE, data-interpretation and duplicate-key errors become warnings
keywords control handling of input rows that duplicate existing rows on
LOAD
DATA.
on an empty
TABLE). Normally, this makes
REPAIR
to re-create the indexes after loading the file. See
and
SELECT ... INTO OUTFILE
clause, each of its subclauses
or
clause, the defaults are the same as if you had written this:
LINES
and
specify tab and newline characters, respectively.)
'\n'
LOAD DATA INFILE
1074
Syntax
LOAD DATA INFILE
system variable is set to a nonempty directory name, the
Section 13.2.7,
IGNORE
SET foreign_key_checks = 0
table, all nonunique indexes are created in a
MyISAM
LOAD DATA INFILE
before loading the file into the table and using
(TERMINATED
to act as follows when reading input:
on server files, you must
MySQL". For
non-LOCAL
is specified.
IGNORE
"REPLACE
Syntax".
keyword is specified.
LOCAL
is specified; this is because the
much faster when
Section 8.3.2.1,
statements, the syntax of the
must precede
FIELDS
BY,
[OPTIONALLY] ENCLOSED
load
IGNORE
LINES

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents