Example table:
CREATE TABLE `unicode` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`c1` varchar(50) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8
Python code:
# start python code
import MySQLdb
db = MySQLdb.connect(db='test',user='root',charset='utf8')
c = db.cursor()
zen = u'\u305c\u3093'
c.execute("INSERT INTO unicode (c1) VALUES ('%s')" % (zen,))
c.close()
db.close()
# end python code
Result after executing the above:
mysql> SET NAMES 'utf8';
mysql> SELECT * FROM unicode;
+----+--------+
| id | c1 |
+----+--------+
| 1 | ぜん |
+----+--------+
More about Python and Unicode here:
http://boodebr.org/main/python/all-about-python-and-unicode
Cheers,
Geert
Geert Vanderkelen
Software Developer at Oracle