LOAD DATA INFILE
Sintassi
LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'nome_file' [REPLACE | IGNORE] INTO TABLE nome_tab [CHARACTER SET nome_charset] [{FIELDS | COLUMNS} [TERMINATED BY 'stringa'] [[OPTIONALLY] ENCLOSED BY 'carattere'] [ESCAPED BY 'carattere'] ] [LINES [STARTING BY 'stringa'] [TERMINATED BY 'stringa'] ] [IGNORE num LINES] [(nome_colonna_o_variabile_utente,...)] [SET nome_col = espr,...]
Spiegazione
L'istruzione LOAD DATA INFILE
copia le righe da un file di testo a una tabella a una velocità molto alta. Il nome del file deve essere specificato come stringa letterale.
LOAD DATA INFILE
è il complemento di SELECT ... INTO OUTFILE
.
Per scrivere dati da una tabella ad un file si usa SELECT ... INTO OUTFILE
. Per copiare dati da una file ad una tabella si usa LOAD DATA INFILE
. La sintassi delle clausole FIELDS
e LINES
è la stessa per entrambe le istruzioni. Entrambe le clausole sono opzionali, ma se sono specificate entrambe FIELDS
deve precedere LINES
.
The character set indicated by the character_set_database
system variable
is used to interpret the information in the file. SET NAMES
and the
setting of character_set_client
do not affect interpretation of input. If
the contents of the input file use a character set that differs from the
default, it is usually preferable to specify the character set of the file by
using the CHARACTER SET
clause, which is available. A character set of
binary
specifies "no conversion."
LOAD DATA INFILE
interprets all fields in the file as having the same
character set, regardless of the data types of the columns into which field
values are loaded. For proper interpretation of file contents, you must ensure
that it was written with the correct character set. For example, if you write a
data file with mysqldump -T
or by issuing a SELECT ... INTO OUTFILE
statement in mysql
, be sure to use a
option with --
default-character-setmysqldump
or mysql
so
that output is written in the character set to be used when the file is loaded
with LOAD DATA INFILE
.
Note: It is currently not possible to load data files that use the ucs2
character set.
The character_set_filesystem
system variable controls the interpretation of
the file name.
You can also load data files by using the mysqlimport
utility; it
operates by sending a LOAD DATA INFILE
statement to the server. The
option causes --
localmysqlimport
to read data files from the
client host. You can specify the
option to get better
performance over slow networks if the client and server support the compressed
protocol.--
compress