MySQL data guides derive method and tool
Tuesday, March 03, 2009 by rain
The interpreter states:The partial content that article content comes from one book of Sam's Teach Yourself MySQL In 21 Days,English of By Mark Maslakowski is textual the person that copyright belongs to original work is all,The partial interpreter of Chinese has somewhat the too clear place that original book of; of additions and deletions tells has cutout,The not clear place that tell has add;If have the place with the interpreter's incorrect perhaps misgivings,Ask point out mistakes so that they can be corrected.
Translator:David Euler, SCU. De_euler-david@www.yahoo.com.cn
1) the grammar introduction of.mysqlimport:
Mysqlimport is located in in Mysql/bin catalog,One be Mysql loads (perhaps say to guide) a of data very effective tool.This is tool of travel of a command.Two parameter and many options can offer an alternative.This tool file of a text (Text File) in the database that guides you are appointed and watch.In saying we want to guide data into the watch Custermers in database Meet_A_Geek from inside file Customers.txt for example:Mysqlimport Meet_A_Geek Customers.txt
Notice:Customers.txt is we should guide here the text file of data,And Meet_A_Geek is the database that we should operate,The watch name in the database is Customers,The data format of here text file must agree with the format in Customers watch,Otherwise Mysqlimport command will make mistake.
The name that expresses among them is to guide the first full stop of the file (. ) in front file string,Another example:Mysqlimport Meet_A_Geek Cus.to.mers.txt
So we will guide the content in the file into the Cus watch in database Meet_A_Geek.
In the example above,Use two parameter only,Did not use more option,The option of Mysqlimport introduces below
2) the commonly used option of.mysqlimport introduces:
Option function
- D Or- - Delete new data guides data data is deleted to express all medium information before data table is medium
- F Or- - no matter whether Force encounters a mistake,Mysqlimport will continue compulsively to insert data
- I Or- - Ignore Mysqlimport is jumped over or those have oversight identical and exclusive
The travel of key word,Guide the data into the file will by oversight.
- before data of L Or -lock-tables is inserted, chain watch,Prevented so,When you are updating a database,The inquiry of the user and be affected newlier.
- R Or -replace this option and - the effect of I option is adverse;This option records what there is identical and only key word in replacing a list.
- - when Fields-enclosed- By= Char appoints the record of the data in text file, rise with what draw together,The data below a lot of circumstances rises with double quote draw together.The data below acquiescent circumstance is to do not have what be removed by character draw together.
- - the separator between the value that Fields-terminated- By=char assigns each data,In the file of full stop space,Separator is full stop.You can appoint the separator between data with this option.Acquiescent separator is to jump case accord with (Tab)
- - this option of Lines-terminated- By=str appoints the travel in text file and travel between the disjunctive string of data or character.The Mysqlimport below acquiescent circumstance is a separator with Newline.You can choose to replace a single character with a string:Go newly or a carriage return.The option with Mysqlimport commonly used command still has - V shows version (Version) ,- P clew inputs a password (Password) etc.
3) . Example:Guide one is the file of separator with comma
The format of the travel in the file is such:
"1" , "ORD89876" , "1 Dozen Roses" , "19991226 "
Our task is to want to guide the data inside this file into the form Orders in database Meet_A_Geek,We use this order: Fields-terminated-by= of - of Fields-enclosed-by=" of - of Prl of Bin/mysqlimport -, meet_A_Geek Orders.txt
This command may look very accurate,After was familiar with when you nevertheless,This is very simple.The first part,Bin/mysqlimport, telling an operating system you want the order that move is the Mysqlimport below Mysql/bin catalog,Option P is requirement input password,Ask you are altering so the password is inputted before the database,The operation rises the meeting is safer.Because we want a list,we used R option is the data in there is the record that repeats only key word to replace a document in medium only key word and file record.We express the data in sheet is not newest,The data in needing to use a document goes updating,Use R consequently this option,In replacing a database already some records.The action of L option is chain when we insert data watch,The operation that when preventing an user to replace a list in us so, has inquire or be changinged to the watch.