【问题标题】:MySQL > Not showing data even when size is increasing and rows can be seen on a database viewerMySQL > 即使大小增加并且可以在数据库查看器上看到行,也不显示数据
【发布时间】:2016-11-16 11:55:33
【问题描述】:

在 mysql 数据库中插入大量数据。 遵循的步骤是: https://affiliate.itunes.apple.com/resources/documentation/epfimporter/

问题是除了我看不到数据之外,一切似乎都很顺利。我也在桌子上尝试了select count(*),它返回 0 行。 我在命令行上也试过。

数据库的大小正在增加。

我正在使用 Sequel Pro,当我按下刷新时,它会显示行数。随着我的脚本不断插入更多数据,行数和大小也在增加。但是加载器完成后,行数显示为0,但大小仍然是一个很大的数字。

摄取器代码 sn-p。完整的代码可以在上面给出的链接中找到。

def _populateTable(self, tableName, resumeNum=0, isIncremental=False, skipKeyViolators=False):
    """
    Populate tableName with data fetched by the parser, first advancing to resumePos.

    For Full imports, if skipKeyViolators is True, any insertions which would violate the primary key constraint
    will be skipped and won't log errors.
    """
    #REPLACE is a MySQL extension which inserts if the key is new, or deletes and inserts if the key is a duplicate
    commandString = ("REPLACE" if isIncremental else "INSERT")
    ignoreString = ("IGNORE" if (skipKeyViolators and not isIncremental) else "")
    exStrTemplate = """%s %s INTO %s %s VALUES %s"""
    colNamesStr = "(%s)" % (", ".join(self.parser.columnNames))

    self.parser.seekToRecord(resumeNum) #advance to resumeNum
    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=300)
        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.close()

我什至等待脚本完成,但没有结果。

MySQl 版本 5.6.23

非常感谢任何帮助。

【问题讨论】:

  • 显示实际的插入命令。
  • @johnelemans 我已经给出了一个链接。它是 iTunes 提供的代码,您可以找到正在插入的文件 EPFIgester.py
  • 重现您面临的问题所需的所有信息都应直接显示在 Stackoverflow 上。
  • @Jocelyn 添加了代码 sn-p。

标签: mysql innodb itunes mysql-python


【解决方案1】:

听起来像

  • 你有autocommit=0
  • 没有做START TRANSACTION
  • 尚未完成COMMIT

构建多行INSERTs 是个好主意。 200还不错。但提交(或autocommit)每一个。

REPLACE不如INSERT .. ON DUPLICATE KEY UPDATE;但后者有不同的语法。

使用字符集转换例程 (unicode()) 让我害怕。这通常会导致混乱。如果一切设置正确,则不需要显式转换。

【讨论】:

  • 感谢您的一些见解,如果它修复了某些问题并在此处更新,我会研究这些。虽然它是 iTunes 提供的库,但我认为不会有问题。
  • 谢谢。提交丢失。虽然我没有看到 autocommit=0
  • 建议您向 iTunes 提交错误。
  • 也许自动提交在某处被默认为 0。 (就我个人而言,我认为 =0 应该被禁止——对于像你这样的情况。)
猜你喜欢
  • 1970-01-01
  • 2013-01-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-03
  • 2015-03-09
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多