Python Mysql没有插入其他语言

时间:2016-10-25 17:13:29

标签: python mysql

我试图插入多种语言支持。

所以我将名字字段整理设置为utf-8 general cli。

当我在workbenck中直接运行下面的sql查询时。它插入了相同的语言。

    INSERT INTO `samba`.`userprofile`(`email`,
    `name`,
    `pass`,`passcode`)
    VALUES
    ('ands@gme1d22.com','ญาณทัสนะ','ana','awer');

当我尝试插入python脚本时,我插入的内容像“à¸à¸²à¸”à¸-ัสนర“

这是我的python脚本。

# -*- coding: utf-8 -*-

from gettext import gettext as _

import MySQLdb

try:
        db = MySQLdb.connect("localhost","root","password","samba" )
        cursor = db.cursor()
except:
        print "Database Not Connected"
        sys.exit(1)




query  = """  
        INSERT INTO `samba`.`userprofile`(`email`,
        `name`,
        `pass`,`passcode`)
        VALUES
        ('ands@gme1d22.com','ญาณทัสนะ','ana','awer');
         """

cursor.execute(query)
db.commit()

0 个答案:

没有答案