MySQL > 即使大小增加也不显示数据,并且可以在数据库查看器上看到行

MySQL > Not showing data even when size is increasing and rows can be seen on a database viewer

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

问题是除了我看不到数据外,一切似乎都很顺利。我也在 table 上尝试了 select count(*),它 returns 0 行。 我在命令行上尝试了同样的方法。

数据库的大小正在增加。

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

摄取代码片段。完整代码可以在上面给出的 link 中找到。

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

非常感谢任何帮助。

听起来像

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

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

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

使用字符集转换例程 (unicode()) 吓到我了。这通常会导致一团糟。如果一切设置正确,则不需要显式转换。