下面的一堆数据:
Afghanistan
Africa
Albania
Algeria
American Samoa
Andorra
Angola
Anguilla
Antarctica
Antigua & Barbuda
Antilles, Netherlands
Arabia, Saudi
Argentina
Armenia
Aruba
Asia
Australia
Austria
Azerbaijan
Bahamas, The
Bahrain
Bangladesh
Barbados我想插入到数据库的一个表的一个字段里面,一个一行,这个有什么好办法没?我用下面的sql失败,  不知道有什么好的方法??select  Afghanistan
union all
select  Africa
union all
select  Albania
union all
select  Algeria
union all
select  American Samoa
union all
select  Andorra
union all
select  Angola
union all
select  Anguilla
union all
select  Antarctica
union all
select  Antigua & Barbuda
union all
select  Antilles, Netherlands
union all
select  Arabia, Saudi
union all
select  Argentina
union all
select  Armenia
union all
select  Aruba
union all
select  Asia
union all
select  Australia
union all
select  Austria
union all
select  Azerbaijan
union all
select  Bahamas, The
union all
select  Bahrain
union all
select  Bangladesh
union all
select  Barbados

解决方案 »

  1.   

    把你这个写到一个文件中如a.txt执行下面语句即可load data infile 'a.txt' into table yourtable (yourcolumn);
      

  2.   

    insert into a(a) values ('Algeria'), ('American Samoa' ), ('Andorra' ), ('Angola' ), ('Anguilla') , ('Antarctica') 
      

  3.   

    不懂你想问什么?select  'Afghanistan'
    union all
    select  'Africa'
    ....你自己二楼不已经给出答案了吗?
      

  4.   

    load data [low_priority] [local] infile 'file_name.txt' [replace | ignore]  into table tbl_name  [fields  [terminated by 't']                 //遇到某符号(t表示符号)分隔的字符串跳过  [optionally | enclosed by '']    //用于控制字段的引号  [escaped by '\' ]]                   //去掉指定字符  [lines terminated by 'n']        //遇到n符号‘行’终止  [ignore number lines]            //忽略某行  [(col_name,...)]                     //用来设定只输入资料到某些字段   例如:mysql >load data infile '/tmp/lq20.txt' into table gk2009.mylq fields terminated by ',' enclosed by '"' lines terminated by '\r\n';   ***如果指定关键词low_priority(低优先级),LOAD DATA语句的执行被推迟到没有其他客户读取表后。  ***如果指定LOCAL关键词,从客户主机读文件。如果LOCAL没指定,文件必须位于服务器上。  ***replace和ignore关键词控制对现有的唯一键记录的重复的处理。如果指定replace,新行将代替有相同的唯一键值的现有行。如果你指定 ignore,跳过有唯一键的现有行的重复行的输入。如果你不指定任何一个选项,当找到重复键键时,出现一个错误,并且文本文件的余下部分被忽略。(如果你使用local关键词从一个本地文件装载数据,服务器没有办法在操作的当中停止文件的传输,因此缺省的行为好像ignore被指定一样。)  ***注意检查导入后有没有导入不可见符号,例如\r
    mysql> load data infile '/a/a' into table a(a); 
    ERROR 1085 (HY000): The file '/a/a' must be in the database directory or be readable by all
    mysql> load data infile '/a/a' into table aa.a fields terminated by ',' enclosed by '"' lines terminated by '\r\n';
    ERROR 1085 (HY000): The file '/a/a' must be in the database directory or be readable by all
    mysql> load data infile a.txt into table a(a); 
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a.txt into table a(a)' at line 1
    mysql> load data infile a.txt into table a; 
    ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'a.txt into table a' at line 1
    mysql> load data infile 'a.txt' into table a; 
    Query OK, 4 rows affected (0.02 sec)
    Records: 4  Deleted: 0  Skipped: 0  Warnings: 0