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 27 • THE MANY MYSQL CLIENTS■ Tip Although, like all other utilities, you can learn more about mysqlhotcopy by invoking it with the --helpoption, more thorough documentation can be had via perldoc mysqlhotcopy.mysqlimportThe mysqlimport utility offers a convenient means for importing data from a delimited text file into adatabase. It is invoked using the following syntax:%>mysqlimport [options] database textfile1 [textfile2...]This utility is particularly useful when migrating to <strong>MySQL</strong> from another database product or legacysystem, because the vast majority of storage solutions (<strong>MySQL</strong> included) are capable of both creatingand parsing delimited data. An example of a delimited datafile follows:Hemingway, Ernest\tThe Sun Also Rises\t1926\nSteinbeck, John\tOf Mice and Men\t1937\nGolding, William\tLord of the Flies\t1954In this example, each item (field) of data is delimited by a tab (\t) and each row by a newline (\n).Keep in mind that the delimiting characters are a matter of choice because most modern storagesolutions offer a means for specifying both the column and the row delimiters when creating andreading delimited files. Suppose these rows were placed in a file called books.txt and you wanted to readthis data from and write it to a database aptly called books:%>mysqlimport -u root -p --fields-terminated-by=\t \>--lines-terminated-by=\n books books.sqlThe executing user requires INSERT permissions for writing the data to the given table, in addition toFILE privileges to make use of mysqlimport. See Chapter 29 for more information about setting userprivileges.myisamchkAlthough it is widely acknowledged that <strong>MySQL</strong> is quite stable, certain conditions out of its control canresult in corrupt tables. Such corruption can wreak all sorts of havoc, including preventing furtherinsertions or updates, and even resulting in the temporary (and in extreme cases, permanent) loss ofdata. If you experience any table errors or oddities, you can use the myisamchk utility to check MyISAMtable indices for corruption and repair them if necessary. It’s invoked using the following syntax:%>myisamchk [options] /path/to/table_name.MYIIn the absence of any options, myisamchk just checks the designated table for corruption. Forexample, suppose you want to check the table named staff that resides in the corporate database:%>myisamchk /usr/local/mysql/data/corporate/staff.MYI519

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

Saved successfully!

Ooh no, something went wrong!