错误:1210:执行准备好的语句的参数数量不正确 [英] Error: 1210: Incorrect number of arguments executing prepared statement

查看:375
本文介绍了错误:1210:执行准备好的语句的参数数量不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Python将数据插入MySQL.

I'm trying to insert data into MySQL using Python.

此错误的原因是什么?

ProgrammingError:1210:执行的参数数量不正确 准备好的声明

ProgrammingError: 1210: Incorrect number of arguments executing prepared statement

我的python代码:

My python codes:

connection = mysql.connector.connect(host='localhost',
                         database='popsww2017',
                         user='root',
                         password='')
records_to_insert = [('---2q7vcZGU', 'Partner-provided', '35', '9s1Pvm0U8Gg8mRavZhVXdg', 'A663893851990558', '1066/2016/HDHT-Pops-Kha Ly', '1467', '0.100598')]
sql_insert_query = "INSERT INTO raw_music (`Video_ID`, `Content_Type`, `Video_Duration`, `Channel_ID`, `Asset_ID`, `Asset_Labels`, `Owned_Views`, `Partner_Revenue`) VALUES ( '%s', '%s' , '%s' , '%s', '%s' , '%s' , '%s' , '%s') "
cursor = connection.cursor(prepared=True)
result  = cursor.executemany(sql_insert_query,records_to_insert)
connection.commit()

我的桌子:

Video_ID    varchar(50) utf8_unicode_ci     
Content_Type    varchar(100)    utf16_unicode_ci        
Video_Duration  int(11)         
Channel_ID  varchar(100)    utf8_unicode_ci     
Asset_ID    varchar(50) utf32_unicode_ci        
Asset_Labels    varchar(400)    utf32_unicode_ci        
Owned_Views int(20)         
Partner_Revenue float   

推荐答案

您忘记了传递

MySQLCursor.executemany()方法 语法:

MySQLCursor.executemany() Method Syntax:

cursor.executemany(operation, seq_of_params)

此方法准备数据库操作(查询或命令),并针对序列seq_of_params中找到的所有参数序列或映射执行该操作.

This method prepares a database operation (query or command) and executes it against all parameter sequences or mappings found in the sequence seq_of_params.

同样,您的语法错误(删除引号),请改用以下内容:

Also your syntax is wrong (remove quotes), use the following instead:

records_to_insert = [('---2q7vcZGU', 'Partner-provided', '35', '9s1Pvm0U8Gg8mRavZhVXdg', 'A663893851990558', '1066/2016/HDHT-Pops-Kha Ly', '1467', '0.100598')]
sql_insert_query = "INSERT INTO raw_music (`Video_ID`, `Content_Type`, `Video_Duration`, `Channel_ID`, `Asset_ID`, `Asset_Labels`, `Owned_Views`, `Partner_Revenue`) VALUES ( %s, %s , %s , %s, %s , %s , %s , %s) "
cursor = connection.cursor(prepared=True)
result  = cursor.executemany(sql_insert_query, records_to_insert)

这篇关于错误:1210:执行准备好的语句的参数数量不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆