1. Home
  2. Docs
  3. MySQL
  4. 备份与恢复
  5. load-data

load-data

语法

load data [low_priority] [local] infile 'file_name txt' [replace | ignore] into table tbl_name
[fields
[terminated by '\t']                 #字段的分隔符(即指定文本文件中列之间的分隔符),默认情况下是一个tab字符(\t)
[OPTIONALLY] enclosed by '']          #字段括起字符,即字段的引用字符
[escaped by'\' ]                #转义字符,默认的是反斜杠(backslash\)
]

[lines
[terminated by '\n']               #每条记录的分隔符,默认为'\n'即为换行符
[ignore number lines]
[(col_name, )]
]

配置

  • secure_file_priv

示例

从文件中以换行符分界导入指定字段数据
load data low_priority infile "/var/lib/mysql-files/words" into table words2(word);

如果遇到导入失败或导入的数据是NULL的话请做如何检查
show global variables like "secure_file_priv";

官方资料

官方文档-LOAD DATA Statement

相关资料

mysql几种读取文件方法的使用

mysql中使用load data infile导入数据的用法

Was this article helpful to you? Yes No

How can we help?