How to Exporter gae data to MySQL?
I have a 'College' model data.
My str_loader.py
is:
class MySQLExporter(bulkloader.Exporter):
def output_entities(self, entity_generator):
conn = MySQLdb.connect(host='localhost',user='root',passwd='root',db='test',charset="utf8")
c = conn.cursor()
for entity in entity_generator:
c.execute("INSERT INTO haha (a,b)开发者_开发知识库 VALUES (%s, %s)",
(entity['cid'], entity['name']))
class Mysql_download(MySQLExporter):
def __init__(self):
MySQLExporter.__init__(self,'College',
[
('cid', str,None),
('name', lambda x: unicode(x, 'utf8'),None),
])
exporters = [Mysql_download]
And it running successful. However, it does not insert data to MySQL.
Try calling .commit()
on the connection after loading the entities.
精彩评论