Saving Python Pickled objects in MySQL db

后端 未结 4 1670
北海茫月
北海茫月 2020-12-14 22:55

I am pickling Python Objects in Django and saving it in MySQL db. So far i have followed these simple rules:

  1. cPickle.dumps(object) #to convert

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-14 23:35

    one more rule: connect to mysql with option charset=utf8?

    UPD1: Sometimes it is a good idea to look at the complete SQL query, I usually do it that way:

    >>> conn = MySQLdb.connect(**db_params)
    >>> "INSERT INTO tbl VALUES (%s)" % conn.literal((your_pickled_item, ))
    

提交回复
热议问题