是“加载数据” MySQL 和 Java 可能没有文件(即在内存中)吗?
我正在优化将约 10TB 数据导入 MySQL 数据库的过程。目前,我可以在当前笔记本电脑上在大约 14 分钟内导入 2.9GB(+0.8GB 索引)。该过程包括读取数据文件(Oracle“.dat”导出)、解析数据、将数据写入 CSV 文件并对其执行“LOAD DATA LOCAL”sql 命令。
是否可以提高导入速度(无需更改硬件)?有没有办法去掉将文件写入文件系统并让MySQL再次读取的步骤。是否可以将内存中的数据直接传输到 MySQL(例如,通过 JDBC 驱动程序)?
预先非常感谢, 约尔格.
I'm in the process of optimizing an import of ~10TB of Data into a MySQL database. Currently, I can import 2.9GB (+0.8GB index) in about 14 minutes on a current laptop. The process includes reading a data file (Oracle ".dat" export), parsing the data, writing the data into a CSV file and executing the "LOAD DATA LOCAL" sql command on it.
Is it possible to increase the import speed (without hardware changes)? Is there a way to remove the step of writing a file to the file system and letting MySQL read it again. Is it possible to stream the data in memory directly to MySQL (e.g., via the JDBC driver)?
Many thanks in advance,
Joerg.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
似乎从 MySQL Connector/J JDBC 驱动程序版本 5.1.3 开始,您可以使用 com.mysql.jdbc.Statement.setLocalInfileInputStream() 方法,在 Java 代码内部,用于“管道”内存格式化字符串/文本到“LOAD DATA INFILE”调用。这意味着您不必必须写出临时文件并从内存中重新读回。请参考:
http://dev .mysql.com/doc/refman/5.1/en/connector-j-reference-implementation-notes.html(页面底部)
此过程也概述于帖子:
http://jeffrick.com/2010/03/23/bulk-insert-into-a-mysql-database
O 'reilly 制作了 涵盖 MySQL/JDBC 性能宝石的 PDF ,指的是这个。
还提到了它与 Hadoop 的用法(高级Java 主题)。
希望这一切都有帮助。
干杯
丰富
It seems that from MySQL Connector/J JDBC driver version 5.1.3 onwards, you can hook up an InputStream reference, using com.mysql.jdbc.Statement.setLocalInfileInputStream() method, internally within your Java code, to 'pipe' your in-memory formatted string/text to the 'LOAD DATA INFILE' call. This means you do not have to write out and re-read a temporary file back from memory. Please refer to:
http://dev.mysql.com/doc/refman/5.1/en/connector-j-reference-implementation-notes.html (bottom of page)
The process is also outlined in this post:
http://jeffrick.com/2010/03/23/bulk-insert-into-a-mysql-database
O'reilly produced a PDF covering MySQL/JDBC performance gems, which refers to this.
There is also mention of it's usage with Hadoop (advanced Java topic).
Hope this all helps.
Cheers
Rich
实际的工作代码很难获得,所以这里有一些:
Actual working code for this was hard to come by, so here's some: