LOAD DATA INFILE

Stai visualizzando una vecchia versione di questo article. Visualizza la versione più recente.

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 --default-character-set option with mysqldump 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 --local option causes mysqlimport to read data files from the client host. You can specify the --compress option to get better performance over slow networks if the client and server support the compressed protocol.

See Also

Commenti

Sto caricando i commenti......
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.