提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
前言
一、Mysql的批量插入
1、使用多值插入语句
INSERT INTO table_name (column1, column2, column3)
VALUES
(value1_1, value1_2, value1_3),
(value2_1, value2_2, value2_3),
(value3_1, value3_2, value3_3);
2、使用INSERT INTO … SELECT
INSERT INTO target_table (column1, column2, column3)
SELECT source_column1, source_column2, source_column3
FROM source_table
WHERE some_condition;
3、使用LOAD DATA INFILE
LOAD DATA INFILE '/path/to/datafile.csv'
INTO TABLE table_name
FIELDS TERMINATED BY ',' ENCLOSED BY '"'
LINES TERMINATED BY '\n';