在MySQL数据库中导入非常长的字符串列表

在MySQL数据库中导入非常长的字符串列表,mysql,import,Mysql,Import,我有一个非常非常长的单词列表,每一个都在一行上。像这样: abactor abaculi abaculus abacus abacuses abada ... ... ... zythum zyzzyva zyzzyvas 我想将所有这些单词导入MySql数据库。最有效的方法是什么?1创建表格以存储数据: create table words ( id int not null auto_increment primary key, word varchar(255), index

我有一个非常非常长的单词列表,每一个都在一行上。像这样:

abactor
abaculi
abaculus
abacus
abacuses
abada
...
...
...
zythum
zyzzyva
zyzzyvas

我想将所有这些单词导入MySql数据库。最有效的方法是什么?

1创建表格以存储数据:

create table words
(
  id int not null auto_increment primary key,
  word varchar(255),
  index(word)
);
2使用
load data
命令在表中插入文本文件

load data local infile '/tmp/words.txt' into table words(word);
'/tmp/words.txt'
是您的文件

3检查是否一切正常:

select * from words limit 9;
+----+----------+
| id | word     |
+----+----------+
|  1 | abactor  |
|  2 | abaculi  |
|  3 | abaculus |
|  4 | abacus   |
|  5 | abacuses |
|  6 | abada    |
|  7 | zythum   |
|  8 | zyzzyva  |
|  9 | zyzzyvas |
+----+----------+

1创建表以存储数据:

create table words
(
  id int not null auto_increment primary key,
  word varchar(255),
  index(word)
);
2使用
load data
命令在表中插入文本文件

load data local infile '/tmp/words.txt' into table words(word);
'/tmp/words.txt'
是您的文件

3检查是否一切正常:

select * from words limit 9;
+----+----------+
| id | word     |
+----+----------+
|  1 | abactor  |
|  2 | abaculi  |
|  3 | abaculus |
|  4 | abacus   |
|  5 | abacuses |
|  6 | abada    |
|  7 | zythum   |
|  8 | zyzzyva  |
|  9 | zyzzyvas |
+----+----------+

首先,您没有指定正在使用的语言。但无论如何,我要假设您已经创建了一个数据库和表,并在MySQL和编程语言之间建立了连接。以Java为例

  • 打开包含单词列表的文本文件
  • 使用while循环将单词插入数据库
  • 代码:
    首先,您没有指定正在使用的语言。但无论如何,我要假设您已经创建了一个数据库和表,并在MySQL和编程语言之间建立了连接。以Java为例

  • 打开包含单词列表的文本文件
  • 使用while循环将单词插入数据库
  • 代码: