The use of the following methods:
The code is as follows |
Copy Code |
Mysql>load data local infile "d:/ab.txt" into table Mytbl (name,age); |
How to load data with back slash (backslash) "" data
Because if you do not specify the fields clause, the default value is the value that assumes that you write the following statement:
The code is as follows |
Copy Code |
FIELDS terminated by ' t ' enclosed by ' escaped by '
|
So, if your data has a backslash (backslash) "", the data will be truncated problem. This problem occurs as long as the following fields clause is written
The code is as follows |
Copy Code |
FIELDS terminated by ' t ' enclosed by ' escaped by ' |
Using the commands above, you can import the contents of the D:/ab.txt file into the table mytbl, where name and age are the fields of the table mytbl, corresponding to the data for each row in the Ab.txt file. If you do not specify –enable-local-infile when compiling the MySQL installation, the following error will be reported when using the above command:
ERROR 1148 (42000): The used command isn't allowed with this MySQL version
There are two solutions, one is to recompile the installation plus the above parameters, but directly with the command line execution, as follows:
The code is as follows |
Copy Code |
Mysql-uroot-proot mydb_name--local-infile=1-e ' load data local infile ' d:/ab.txt to Table Mytbl (name,age) ' |
Tested one, when importing 3 million data, the time spent using the load Data command was about 3 minutes.
When to load, insert only specific columns
For example, there are columns in the table that are more than meta data. You can specify the name of the field to insert at load time.
The code for the example is as follows:
The code is as follows |
Copy Code |
LOAD DATA INFILE ' ~/data.txt ' Into TABLE fb0505 CHARACTER SET GBK FIELDS terminated by ' t ' enclosed by ' escaped by ' LINES terminated by ' n ' starting by ' (Seller_id,fb_type,fb_date,item_url); |
One of the table fb0505 has a list of IDs.
The table was built with MyISAM, adjusting the parameter values of several sessions
code is as follows |
copy code |
SET session bulk_insert_buffer_size=256217728; SET session myisam_sort_buffer_size=256217728; |