1). Introduction to Mysqlimport Syntax:
Mysqlimport is located in the Mysql/bin directory and is a very effective tool for MySQL to load (or import) data. This is a command-line tool. There are two parameters and a 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 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 our text file to import 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 consistent with the record format in the Customers table. Otherwise the Mysqlimport command will be faulted.
The name of the table is the first full period (.) file string in the import file, and 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 above example, only two parameters are used, and no more options are used, the following describes the options for Mysqlimport
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 the data to be inserted regardless of whether or not an error is encountered
-I or--ignore mysqlimport skip or ignore those with the same unique
keyword, the data in the import file is ignored.
-L or-lock-tables data is inserted before locking the table, which prevents the
When you update a database, users ' queries and updates are affected.
-R or-replace This option is the opposite of the-I option; this option overrides
A record with the same unique keyword in the table.
--fields-enclosed-by= Char
Specifies what the data in the text file is to be recorded in, in many cases
The data is enclosed in double quotation marks. By default, the data is not surround by the word.
--fields-terminated-by=char
Specifies the delimiter between the values of each data, in a period-delimited file,
The delimiter is a period. You can use this option to specify a delimiter between data.
The default delimiter is Jump Geff (Tab)
--lines-terminated-by=str
This option specifies a delimited string of data between rows in a text file and lines
or character. By default, Mysqlimport with newline as the line delimiter.
You can choose to replace a single character with a string:
A new line or a carriage return.
The common options for the Mysqlimport command are the-v display (version), the-P prompt for a password (password), and so on.
3). Example: Import a comma-delimited file
The record format for the rows in the file is this:
"1", "ORD89876", "1 dozen Roses", "19991226"
Our mission is to import the data from this file into the table orders in the database Meet_a_geek,
We use this command:
Bin/mysqlimport–prl–fields-enclosed-by= "–fields-terminated-by=, Meet_a_geek Orders.txt
This command may seem uncomfortable, but when you're familiar with it, it's very simple. The first part, Bin/mysqlimport, tells the operating system that you want to run the command is the Mysql/bin directory mysqlimport, option p is required to enter a password, so that you can change the database before you enter the password, the operation will be more secure. We used the R option because we wanted to replace the unique keyword in the table with the record in the file with the duplicate unique keyword in the document. The data in our form is not up-to-date and needs to be updated with the data in the file, thus replacing the existing records in the database with the R option. The function of the L option is to lock the table when we insert the data, which prevents the user from querying or changing the table when we update the table.