使用 MySQL LOAD DATA 命令过滤正在加载的数据
我正在使用以下命令。
LOAD DATA INFILE 'source.txt'
INTO TABLE tblData
CHARACTER SET utf8
FIELDS TERMINATED BY '\t';
这工作正常,但我得到的 source.txt 是一个 800MB 的文件,其中只有我需要的 10% 行。我无法在加载之前对文本文件进行过滤。我可以根据某一特定列的值过滤结果。有没有办法可以在加载语句中指定此条件,以便仅加载所需的行。
I am using the following command.
LOAD DATA INFILE 'source.txt'
INTO TABLE tblData
CHARACTER SET utf8
FIELDS TERMINATED BY '\t';
This works fine, but the source.txt that I get is an 800MB file with only 10% rows that are required by me. I cannot do the filtering on the text file before load. I can filter my results based on the value of one specific column. Is there a way I can specify this condition in my load statement so only the required rows are loaded.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,至少不使用
LOAD DATA INFILE
。但是,您可以创建一个脚本来解析您的文件并仅插入符合您条件的记录
Nope, at least not with
LOAD DATA INFILE
.You can however create a script that parses your file and only inserts the records that matches your criteria
您可以让脚本创建一个临时文件,将 LOAD DATA INFILE 调用到临时文件中,然后将临时文件过滤到最终目标。
如果您的系统配置为确保临时文件保留在内存中,您仍然应该获得良好的性能。
You can have your script create a temporary file, call LOAD DATA INFILE into the temporary file, and then filter the temporary file into the final destination.
If your system is configured to make sure the temporary file stays in memory, you should still get good performance.