出现"mysql server has gone away"的错误,应该是mysql超时了.到底mysql一次可以导入多少数据我也不是很清楚,不过我试过一次导上300万的数据,并没有出现你所说的问题,我使用的命令是load data infile "C:/records.txt" into table records fields terminated by ',' enclosed by '"' lines terminated by '\r\n'下面再说我导的过程:
1.建一个同样结构的新表,例如:我的表records 有两个字段id 和name,
create table records (id varchar(16) not null, name varchar(100) not null) engine=myisam;
不要创建任何索引,一切等导好数据再来创建.
2.创建records.txt文件,里面的数据要符合下面的格式,或者你自己喜欢的格式
例如:
"1234567890","里面的数据要符合下面的格式,或者你自己喜欢的格式"
要想将数据导出成这样的格式可以,使用以下命令
select * into outfile "C:/records.txt" fields terminated by ',' enclosed by '"' lines terminated by '\r\n' from table
当然如果你的数据量太大的话,上面的导出数据的SQL语句还可以加上条件.
select * into outfile "C:/records.txt" fields terminated by ',' enclosed by '"' lines terminated by '\r\n' from table where id<'10000000'
不过上面的语句效率不是很好,可能会慢一点.3.records.txt文件准备好后,就可以使用下面的命令来导入数据了
load data infile "C:/records.txt" into table records fields terminated by ',' enclosed by '"' lines terminated by '\r\n'4.数据导入完成后就要重新创建索引,以搞高查询速度.