11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

www.it-ebooks.infoCHAPTER 38 • IMPORTING AND EXPORTING DATAImporting Data with LOAD DATA INFILEThe LOAD DATA INFILE statement, a command that is executed much like a query typically from withinthe mysql client, is used to import delimited text files into a <strong>MySQL</strong> table. Its generalized syntax follows:LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name'[REPLACE | IGNORE]INTO TABLE table_name[CHARACTER SET charset_name][FIELDS[TERMINATED BY 'character'] [[OPTIONALLY] ENCLOSED BY 'character'][ESCAPED BY 'character']][LINES[STARTING BY 'character'] [TERMINATED BY 'character']][IGNORE number lines][(column_name, ...)][SET column_name = expression, ...)]Certainly one of the longer <strong>MySQL</strong> query commands seen thus far, isn’t it? Yet it’s this widearray of options that makes it so powerful. Each option is introduced next:• LOW PRIORITY: This option forces execution of the command to be delayeduntil no other clients are reading from the table.• CONCURRENT: Used in conjunction with a MyISAM table, this option allowsother threads to retrieve data from the target table while the command isexecuting.• LOCAL: This option declares that the target infile must reside on the clientside. If omitted, the target infile must reside on the same server hosting the<strong>MySQL</strong> database. When LOCAL is used, the path to the file can be eitherabsolute or relative according to the present location. When omitted, thepath can be absolute, local, or, if not present, assumed to reside in <strong>MySQL</strong>’sdesignated database directory or in the presently chosen database directory.• REPLACE: This option results in the replacement of existing rows with newrows possessing identical primary or unique keys.• IGNORE: Including this option has the opposite effect of REPLACE. Read-inrows with primary or unique keys matching an existing table row will beignored.• CHARACTER SET charset_name: <strong>MySQL</strong> will presume the input file containscharacters matching the character set assigned to the system variablecharacter_set_database. If the characters do not match this setting, use thisoption to identify the file’s character set.• FIELDS TERMINATED BY 'character': This option signals how fields will beterminated. Therefore, FIELDS TERMINATED BY ',' means that each field willend with a comma, like so:12312,55521,2010-12-19 01:30:45,10.75,3.00,13.75721

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!