怎样把txt文件中的数据导入到mysql数据库中去。
txt文件中只有数据没有其他的东西,

解决方案 »

  1.   


    比如你的路径是:C:\example.txt
    你的表是table1
    example.txt内容为:1,2,3,4
    5,6,7,8
    ...
    load data infile 'c:\\example.txt' into table table1 fields terminated by ',' lines terminated by '\n';
    如果你的分隔符不是一致的,可以用EDITPLUS等工具的正则替换模式替换成一致的分隔符,然后导入即可。
    如果数据格式是这样:
    "1","2","3","4"
    "5","6","7","8"
    ...
    load data infile 'c:\\example.txt' into table table1 fields terminated by ',' optionally enclosed by '"' lines terminated by '\n'
    详情见:
      

  2.   

    http://dev.mysql.com/doc/refman/5.0/en/load-data.html
      

  3.   

    写程序读取txt文件,插入数据库不就好了吗
      

  4.   

    还有就是这一点,如果数据格式是这个样子的话:"1","2","3","4"
    "5","6","7","8"
    直接可以把这个文件比如my.txt改为my.csv,然后建立一个相同SCHEMA的表,不过她的类型是CSV的。这样就直接是数据了。不用导入。具体查看:MYSQL手册中关于CSV引擎的介绍。