【问题标题】:mySQLdb connection Returns a Truncated OutputmySQLdb 连接返回截断的输出
【发布时间】:2018-02-27 15:49:04
【问题描述】:

我正在尝试远程连接到运行存储过程并返回一个大文件作为输出的 sql 服务器。

当我在 SQLbox 上本地运行文件时,它可以正常运行并按预期返回约 800,000 行,但当我尝试使用 python 中的 mySQLdb 库运行它时,它会收到仅约 6000 行的截断输出。

它对于较小的数据运行良好,所以我猜有一些结果限制正在发挥作用。

我确定有一些属性需要在某处更改,但 pypi 库上似乎没有任何相关文档。

出于解释的目的,我在下面包含了我的代码:

import MySQLdb
import pandas as pd

connection = MySQLdb.connect(sql_server,sql_admin,sql_pw,sql_db)
sql_command = """call function(4)"""
return pd.read_sql(sql_command, connection)

【问题讨论】:

    标签: python mysql mysql-python mysql-connector-python


    【解决方案1】:

    我能够使用游标解决这个问题。我采用的方法如下所示,希望对其他人有所帮助。

    connection = MySQLdb.connect (host = sql_server, user = sql_admin, passwd = sql_pw, db = sql_db)
    cursor = connection.cursor ()
    cursor.execute("""call function(4)""")
    data = cursor.fetchall()
    
    frame = []
    for row in data:
        frame.append(row)
    return pd.DataFrame(frame)
    
    cursor.close ()
    # close the connection
    connection.close ()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-30
      • 1970-01-01
      • 2019-04-15
      • 2015-04-02
      • 2012-12-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多