MySQL使用文件导入数据(快速导入大量数据)
禁用索引,加快速度
alter table disable keys
创建表,并且导入数据
CREATE TABLE my_table
(
id int not null AUTO_INCREMENT PRIMARY KEY,
name varchar not null
);
ALTER TABLE my_table DISABLE KEYS;
LOAD DATA INFILE 'data.txt' INTO TABLE mydb.my_table
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 LINES;
ALTER TABLE my_table ENABLE KEYS;