11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

www.it-ebooks.infoCHAPTER 38 • IMPORTING AND EXPORTING DATAUseful OptionsBefore reviewing any examples, take a moment to review many of the most commonly used mysqlimportoptions:• --columns, -c: This option should be used when the number or ordering of thefields in the target file does not match that found in the table. For example,suppose you were inserting the following target file, which orders the fields as id,order_id, sub_total, shipping_cost, total_cost, and order_time:45633,12309,22.04,5.67,27.71,2010-12-19 01:13:42942,12310,11.50,3.40,14.90,2010-12-19 01:15:127879,12311,95.99,15.00,110.99,2010-12-19 01:15:22Yet the sales table presented at the beginning of this chapter lists the fields in thisorder: id, client_id, order_time, sub_total, shipping_cost, and total_cost. Youcan rearrange the input fields during the parsing process so that the data isinserted in the proper location, by including this option:--columns=id,order_id,sub_total,shipping_cost,total_cost,and order_time• --compress, -C: Including this option compresses the data flowing between theclient and the server, assuming that both support compression. This option ismost effective if you’re loading a target file that does not reside on the same serveras the database.• --debug, -#: This option is used to create trace files when debugging.• --delete, -d: This option deletes the target table’s contents before importing thetarget file’s data.• --fields-terminated-by=, --fields-enclosed-by=, --fields-optionallyenclosed-by=,--fields-escaped-by=: These four options determinemysqlimport’s behavior in terms of how both fields and lines are recognizedduring the parsing procedure. See the section “Importing Data with LOAD DATAINFILE” earlier in this chapter for a complete introduction.• --force, -f: Including this option causes mysqlimport to continue execution evenif errors occur during execution.• --help, -?: Including this option generates a short help file and a comprehensivelist of the options discussed in this section.• --host, -h: This option specifies the server location of the target database. Thedefault is localhost.• --ignore, -i: This option causes mysqlimport to ignore any rows located in thetarget file that share the same primary or unique key as a row already located inthe table.• --ignore-lines=n: This option tells mysqlimport to ignore the first n lines of thetarget file. It’s useful when the target file contains header information that shouldbe disregarded.725

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

Saved successfully!

Ooh no, something went wrong!