我有一个包含以下格式数据的数据文件
asd,12,asd,asd,12,adsd,,asdas,None
我在 mysql 中有一个表,它有一个auto increment
intid
和数据文件中的其余列。
现在我正在尝试
query2 = """LOAD DATA LOCAL INFILE 'tmp.txt'
REPLACE INTO TABLE mytable
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\\n'
(a1,a2,a3,a4,a5,a6,a7,a8,a9)
"""
conn = mysql.connector.connect(user=self.db_config.dbusername, password=self.db_config.dbpassword,
host=self.db_config.dbhost,
database='something', client_flags=[ClientFlag.LOCAL_FILES])
cursor = conn.cursor()
cursor.execute(query2)
conn.commit()
cursor.close()
conn.close()
我得到的错误是
类 'mysql.connector.errors.InterfaceError'> 执行操作失败;需要一个整数
由于存在自动增量 ID,我尝试SET ID=None
按照某些帖子的建议进行附加,但结果相同。tmp.txt 与脚本位于同一位置。此响应由 mysql 服务器发送。
那MYSQL Server is on amazon
就是产生差异。
知道是什么原因造成的,或者我们如何调试它?
挖得很深。
错误发生时
execute method in /usr/local/lib/python2.7/site-packages/mysql/connector/cursor.py is called with the query as parameter
cmd_query in /usr/local/lib/python2.7/site-packages/mysql/connector/protocol.py is called
_handle_resultset in /usr/local/lib/python2.7/site-packages/mysql/connector/protocol.py is called
read_lc_int in /usr/local/lib/python2.7/site-packages/mysql/connector/utils.py is called which return (buf,None)
所以_handle_resultset
功能失败了。所以这肯定与LOAD DATA
发送查询时来自服务器的响应有关。