Using Python with MySql and Unicode Characters

To the Point:

To insert unicode values into MySql from Python, use these two parameters:

charset = “utf8″, use_unicode = True

db = MySQLdb.connect(host=”localhost”, user=”root”, passwd=”secret”,db=”dbname”,charset = “utf8″, use_unicode = True)

Additional Information:

You may also need to change the database encoding in your MySql database to utf8.  Do something like this:

ALTER DATABASE DatabaseNameGoesHere DEFAULT CHARACTER SET UTF8;

Leave a Comment