mysql - 如何将 .txt 导入 mysql 文件?

标签 mysql database

如何导入.txt到mysql文件?

我有一个包含数百条记录的 .txt 文件,我想将它导入到 mysql 数据库表中。

例子: word.txt 包含数据:

word_1
word_2
word_3
.
.
.
.
.
word_n

我在mysql数据库中有一张表: tbl_word:

field: id_word, value_word, create_date, update_date

我将 word.txt 文件每一行中的值插入/导入到列 value_word 并设置 id_word AUTO_INCREAMENT,怎么办?

最佳答案

检查 LOAD DATA INFILE Syntax将文件导入表

load data infile 'word.txt'
into tbl_word
fields
  terminated by '\t'
  lines terminated by '\n'
ignore 0 lines
(@c1,@c2,@c3,..,@cN)
set value_word=@c1;

id_word 会自动递增

关于mysql - 如何将 .txt 导入 mysql 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48520898/

相关文章:

php - 按mysql表分组

php - 将一个表的字段与另一个表的其他字段进行比较

php - MYSQL 将输入值存储在一行或多行中

java - 如何使用 iciql 模型生成

python - 从 Cassandra 检索有序计数器的最佳方法

c# - 在一个查询中使用 MySqlCommand 将多条记录插入 MySQL C# (MySQLConnector) & 用于转义引号的命令参数

c# - 使用自定义身份用户时用户角色表上的额外列(ASP.NET 5.2EF 6 和 Identity 2)

php - 他们是将 Drupal-8 和 ionic4 集成用于用户注册和登录的方法吗?

sql-server - 使用 STUFF 或 CONCAT 命令组合 T-SQL 中的行

php - 数据库表无法从 PHP 网站代码正确更新