非常大的写入密集型MySQL导入

我有(我会考虑)大量的纯文本文件,大约400GB,被导入到MySQL数据库(InnoDB引擎)中。 .txt文件的大小从2GB到26GB不等,每个文件都代表数据库中的一个表。 我被给了一个Python脚本来分析.txt文件并构buildSQL语句。 我有一台机器,专门用于以下规格的任务:

  • 操作系统 – Windows 10
  • 32GB内存
  • 4TB硬盘
  • i7 3.40 GHz处理器

我想优化这个导入,尽可能快速和肮脏。 我已经根据堆栈O问题 , MySQL文档和其他来源更改了MySQL my.ini文件中的以下configuration设置:

max_allowed_packet=1073741824; autocommit=0; net_buffer_length=0; foreign_key_check=0; unique_checks=0; innodb_buffer_pool_size=8G; (this made a big difference in speed when I increased from the default of 128M) 

在configuration文件中是否有其他的设置可能会导致MySQL使用机器资源的重要部分(可能是日志logging或caching)? 可能会有另一个瓶颈我失踪?

(注意:不知道这是否与此相关 – 当我开始导入时, mysqld进程将加速使用大约13-15%的系统内存,但是当我停止Python脚本继续时,似乎永远不会清除它导入。我想知道这是否是由于日志和刷新设置搞乱。预先感谢您的任何帮助。)

编辑

这是填充表格的Python脚本的相关部分。 看来脚本正在连接,提交和closures每50,000条logging的连接。 我可以删除函数末尾的conn.commit() ,让MySQL处理提交吗? while (true)下方的注释来自脚本的作者,并且我已经调整了该数字,以使其不超过max_allowed_pa​​cket大小。

  conn = self.connect() while (True): #By default, we concatenate 200 inserts into a single INSERT statement. #a large batch size per insert improves performance, until you start hitting max_packet_size issues. #If you increase MySQL server's max_packet_size, you may get increased performance by increasing maxNum records = self.parser.nextRecords(maxNum=50000) if (not records): break escapedRecords = self._escapeRecords(records) #This will sanitize the records stringList = ["(%s)" % (", ".join(aRecord)) for aRecord in escapedRecords] cur = conn.cursor() colVals = unicode(", ".join(stringList), 'utf-8') exStr = exStrTemplate % (commandString, ignoreString, tableName, colNamesStr, colVals) #unquote NULLs exStr = exStr.replace("'NULL'", "NULL") exStr = exStr.replace("'null'", "NULL") try: cur.execute(exStr) except MySQLdb.Warning, e: LOGGER.warning(str(e)) except MySQLdb.IntegrityError, e: #This is likely a primary key constraint violation; should only be hit if skipKeyViolators is False LOGGER.error("Error %d: %s", e.args[0], e.args[1]) self.lastRecordIngested = self.parser.latestRecordNum recCheck = self._checkProgress() if recCheck: LOGGER.info("...at record %i...", recCheck) conn.commit() conn.close()