Translation statement: This article is from Sams teach yourself MySQL in the book part of the content, by Mark Maslakowski
English original version ownership of the original author, the Chinese part of the translation has a slight additions and deletions, the original book is too clear where there is a deletion, not clear where there is an increase, if there is improper translation or incorrect place, please correct me.
Translator: David Euler,scu. de_euler-david@www.yahoo.com.cn time: 2004/04/24 in Sichuan
1). Introduction to Mysqlimport's grammar
Mysqlimport, located in the Mysql/bin directory, is a very effective tool for MySQL to load (or import) data. This is a command line tool. There are two parameters and a large number of options to choose from. This tool imports a text file into the database and table you specify. Let's say we want to import the data from the file Customers.txt into the table custermers in the database Meet_a_geek:
Mysqlimport Meet_a_geek Customers.txt
Note: Here Customers.txt is the text file where we want to import the data, and Meet_a_geek is the database we want to manipulate, the table name in the database is customers, where the data format of the text file must be the same as the record format in the Customers table, Otherwise the Mysqlimport command will be faulted.
The name of the table is the file string preceding the first period (.) of the import file, another example:
Mysqlimport Meet_a_geek Cus.to.mers.txt
Then we will import the contents of the file into the CUS table in the database Meet_a_geek. In the example above, only two parameters are used, and no more options are used, and the Mysqlimport options are described below
2). Mysqlimport's common options are:
Options feature
-D or--delete all information in the data table before the new data is imported into the datasheet
-F or--force Mysqlimport will force continued insertion of data regardless of whether an error has been encountered
-I or--ignore mysqlimport skips or ignores those that have the same unique
keyword, the data in the import file will be ignored.
-L or-lock-tables Lock the table before the data is inserted, thus preventing the
When you update the database, the user's queries and updates are affected.
-R or-replace This option is the opposite of the-I option; this option replaces
A record in a table that has the same unique keyword.
--fields-enclosed-by= Char
Specifies what is included in the record of the data in the text file, and in many cases
The data is enclosed in double quotes. By default, data is not Fu Guachi by character.
--fields-terminated-by=char
Specifies the separator between the values of each data, in the file separated by the period,
The separator is a period. You can specify the separator between data by using this option.
The default delimiter is Hop Geff (TAB)
--lines-terminated-by=str
This option specifies a delimited string of data between rows and lines in a text file
or characters. By default, Mysqlimport is newline as a row separator.
You can choose to replace a single character with a string:
A new line or a carriage return.
The Mysqlimport command commonly used options include the-v display (version),-p prompts for a password (password), and so on.