我正在使用petl 包构建从 Python 2.7 到 MySQL5.6 的 ETL 管道
我的数据库连接器是 MySQLdb (mysql-python)。
以下代码无法执行:
import MySQLdb as mdb
import petl as etl
con = mdb.connect(host = '127.0.0.1', user = '<someuser>', passwd = '<somepass>')
cur = con.cursor() # get the cursor
cur.execute('DROP SCHEMA IF EXISTS petltest')
cur.execute('CREATE SCHEMA petltest')
cur.execute('USE petltest')
dat = [{'id':1,'name':'One'},
{'id':2,'name':'Two'},
{'id':3,'name':'Three'}]
table = etl.fromdicts(dat) # petl object
etl.todb(table,cur,'table',schema='petltest',create=True)
错误代码是:
ProgrammingError: (1064, '您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,了解在 \'"table" 附近使用的正确语法 (\n\tid INTEGER NOT NULL, \n\tname VARCHAR(5) NOT NULL\n)\' 在第 1 行')
尝试单独创建表或运行 petl.appenddb 时也会出现此错误
我该如何解决/克服这个问题?
谢谢