在查看堆栈交换提供的一些 websocket 方法时,我想将一些数据点保存到 MySQL 数据库中。但是,当我尝试运行executemany
命令时,出现以下错误:
_mysql_exceptions.OperationalError: (1241, 'Operand should contain 1 column(s)')
在环顾 SO 时,我发现了很多这个错误的例子,但他们已经处理了删除SELECT
语句上的括号。我没有使用SELECT
. 我正在尝试INSERT
。
我的代码的一个简短的包含示例如下所示:
import MySQLdb as mdb
db = mdb.connect(host='localhost',user='myuser',db='qs',passwd='mypass',use_unicode=True,charset='utf8')
cur = db.cursor()
db_qry = """INSERT IGNORE INTO questions (id, site_base, title, body_sum, tags, last_act_dt, url, owner_url, owner, api_site) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"""
parms = [(u'mathematica.stackexchange.com',
43248,
u'How to plot “Normalized distance” in this problem',
u"Problem: there are two particles whose equationsof motion both satisfy -n Abs[x[t]]^n/x[t] == x''[t]. But their initial conditions are different: one is x'[0] == 0, x[0] == 2;another is x'[0] == 0, ...",
[u'plotting', u'equation-solving', u'differential-equations', u'numerical-integration', u'notebooks'],
1393801095,
u'http://mathematica.stackexchange.com/questions/43248/how-to-plot-normalized-distance-in-this-problem',
u'http://mathematica.stackexchange.com/users/12706/lawerance', u'Lawerance', u'mathematica')]
cur.executemany(db_qry, parms)
cur.commit()
我用executemany
错了吗?parms
或者错过了我需要在传递给之前清理的列表的另一个方面executemany
?