12, mysql import data

1, mysql command to import

grammar:

mysql -u root -p passwd < runoob.sql

2, source command to import

source aa.sql

3, load data import data using

MySQL provides a LOAD DATA INFILE statement to insert the data. The following examples will read files in the current directory dump.txt, inserting the data file to the current mytbl table in the database.

mysql> LOAD DATA LOCAL INFILE 'dump.txt' INTO TABLE mytbl;

 If you specify LOCAL keyword, read files from the client indicates that the host by path. If not specified, the file on the server reads the file by path.

Can you clear that in the LOAD DATA statement delimiters and line marker column value, but the defaults are tab and newline.

The syntax of the FIELDS and LINES clauses two commands are the same. Two clauses are optional, but if the two are simultaneously specified, FIELDS clause must appear before the LINES clause.

If the user specifies a FIELDS clause, its clauses (TERMINATED BY, [OPTIONALLY] ENCLOSED BY and ESCAPED BY) is also optional, however, the user must specify at least one of them.

mysql> LOAD DATA LOCAL INFILE 'dump.txt' INTO TABLE mytbl
  -> FIELDS TERMINATED BY ':' -> LINES TERMINATED BY '\r\n';

LOAD DATA default data is inserted in the order of the data file and, if not the column in the data file is inserted into the table columns, the columns in the order specified is required.

For example, the order of columns in the data file is a, b, c, but in order to insert the table columns b, c, a, the data import syntax is as follows:

MySQL > the LOAD the DATA INFILE the LOCAL 'dump.txt' -> the INTO TABLE MyTbl ( B , C , A ); . 4, import data using mysqlimport 
    


mysqlimport client provides a command LOAD DATA INFILEQL statement line interface. Most options to mysqlimport correspond directly to LOAD DATA INFILE clause.

Dump.txt in the import file data from the data table to mytbl, use the following command:

$ mysqlimport -u root -p --local mytbl dump.txt password *****

mysqlimport command to specify the option to set the specified format command statement format is as follows:

$ mysqlimport -u root -p --local --fields-terminated-by=":" \ --lines-terminated-by="\r\n" mytbl dump.txt password *****

mysqlimport statement --columns use option to set the order of columns:

$ mysqlimport -u root -p --local --columns=b,c,a \ mytbl dump.txt password *****

mysqlimport introduction of common options

Options Features
-d or --delete Delete all information and data in the data table before the new data into the data table
-f or --force Regardless of whether an error is encountered, mysqlimport forces continue to insert data
-i or --ignore mysqlimport skip or ignore those rows that have the same unique key, data import file will be ignored.
-l or -lock-tables Lock the table before the data is inserted, thus prevented, you update the database when a user's query and update be affected.
-r or -replace This option is the opposite effect with the -i option; this option will have the same unique key record for representatives.
--fields-enclosed- by= char Enclosed in what, in many cases data in double quotation marks when recording data in a specified text file. By default the data is not enclosed in the characters.
--fields-terminated- by=char Specifies the separator between the respective data value in the period-separated file, a separator is a full stop. You can use this option to specify the separator between the data. The default delimiter is tabbing character (Tab)
--lines-terminated- by=str Delimited string or character data between the BOC and the line This option specifies the text file. By default mysqlimport to newline delimiter row. You can choose to use a string to replace a single character: a new line or a carriage return.

mysqlimport command common options as well -v show version (version), -p prompted for a password (password) and so on.

Guess you like

Origin www.cnblogs.com/myheart-new/p/11951235.html
Recommended