1.首先,必须创建一个一一对应的表(字段对应的数据的类型一一对应)。
假如创建一个用户表user:
create table user(
id int unsigned not null primary key auto _incremarent,
username varchar(50) not null,
password varchar(50) not null
)
2.然后,将文件导入到数据库:
假设文件名为user.txt,内容为:
1,test001,test001
2,test002,test002
3,test003,test003
4,test004,test004
执行导入命令(假设文件在c盘根目录):
mysql>load data infile 'c:/user.txt' into table user
>fields terminated by','
>lines terminated by'\r\n'
注意:
1),文件可以使用绝对路径c:/user.txt,否则需放在数据库根目录中
2),因为字段数据之间是用逗号隔开的,所以必i须使用fields terminated by','不然将导入失败。
3),因为Winsows中行以“\r\n”隔开,所以必须lines terminated by'\r\n',