何时为MySQL使用CSV存储引擎? [英] When to use CSV storage engine for MySQL?

查看:231
本文介绍了何时为MySQL使用CSV存储引擎?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

docs 中指出:

CSV存储引擎使用逗号分隔将数据存储在文本文件中 值格式.

The CSV storage engine stores data in text files using comma-separated values format.

这有什么好处?这是我想到的一些东西:

What are the advantages of this? Here are some I can think of:

  1. 您可以使用简单的文本编辑器来编辑CSV文件(但是,可以使用SELECT INTO OUTFILE轻松导出数据)
  2. 可以轻松地导入到电子表格程序中
  3. 轻巧甚至更好的性能(疯狂猜测)
  1. You can edit the CSV files using simple text editor (however, you can export data easily using SELECT INTO OUTFILE)
  2. Can be easily imported into Spreadsheet programs
  3. Lightweight and maybe better performance (wild guess)

有哪些缺点?

  1. 无索引
  2. 无法分区
  3. 没有交易
  4. 不能有NULL值

授予(非详尽的)优缺点列表,在什么实际情况下我应该考虑使用CSV存储引擎而不是其他情况?

Granted this (non-exhaustive) list of advantages and disadvantages, in what practical scenarios should I consider using the CSV storage engine over others?

推荐答案

我很少使用CSV存储引擎.但是,我发现一种有用的方案是用于批量数据导入.

I seldom use the CSV storage engine. One scenario I have found it useful, however, is for bulk data imports.

  1. 使用与我输入的CSV文件匹配的列创建一个表.
  2. 在mysql之外,仅使用shell提示符,将CSV文件mv放入MySQL数据字典中,覆盖属于我刚刚创建的表的.csv文件.
  3. ALTER TABLE mytable ENGINE=InnoDB
  1. Create a table with columns matching my input CSV file.
  2. Outside of mysql, just using a shell prompt, mv the CSV file into the MySQL data dictionary, overwriting the .csv file that belongs to my table I just created.
  3. ALTER TABLE mytable ENGINE=InnoDB

Voilà!使用DDL而不是INSERT或LOAD DATA一步导入一个巨大的CSV数据文件.

Voilà! One-step import of a huge CSV data file using DDL instead of INSERT or LOAD DATA.

当然,它不如INSERT或LOAD DATA灵活,因为您不能对单个列执行NULL或自定义替代,也不能对任何重复值进行替换"或忽略"功能.但是,如果您输入的文件正是您要导入的文件,则可以使导入非常容易.

Granted, it's less flexible than INSERT or LOAD DATA, because you can't do NULLs or custom overrides of individual columns, or any "replace" or "ignore" features for handling duplicate values. But if you have an input file that is exactly what you want to import, it could make the import very easy.

这篇关于何时为MySQL使用CSV存储引擎?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆