What is the best way to achieve speedy inserts of large amounts of data in MySQL?(在 MySQL 中实现快速插入大量数据的最佳方法是什么?)
问题描述
我用 C 语言编写了一个程序来解析大型 XML 文件,然后使用插入语句创建文件.其他一些进程会将文件摄取到 MySQL 数据库中.这些数据将用作索引服务,以便用户可以轻松找到文档.
I have written a program in C to parse large XML files and then create files with insert statements. Some other process would ingest the files into a MySQL database. This data will serve as a indexing service so that users can find documents easily.
我选择 InnoDB 是因为它具有行级锁定的能力.C 程序将在给定调用上生成 500 到 500 万条插入语句.
I have chosen InnoDB for the ability of row-level locking. The C program will be generating any where from 500 to 5 million insert statements on a given invocation.
尽快将所有这些数据输入数据库的最佳方法是什么?要注意的另一件事是数据库位于单独的服务器上.是否值得将文件移至该服务器以加快插入速度?
What is the best way to get all this data into the database as quickly as possible? The other thing to note is that the DB is on a separate server. Is it worth moving the files over to that server to speed up inserts?
此表不会真正更新,但行将被删除.
This table won't really be updated, but rows will be deleted.
推荐答案
- 使用 mysqlimport 工具或 LOAD DATA INFILE 命令.
- 暂时禁用不需要数据完整性的索引
这篇关于在 MySQL 中实现快速插入大量数据的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 MySQL 中实现快速插入大量数据的最佳方法是什么?
基础教程推荐
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 无法解决整理冲突 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
