Проблема. При добавлении русских букв в БД, данные отображаются некорректно(не в той кодировке).
Если добавлять данные с консоли Mysql все нормально.
CREATE DATABASE `mdb` CHARACTER SET utf8 COLLATE utf8_general_ci
CREATE TABLE text ( text char(30) not null ) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
# coding: utf8
import MySQLdb
db = MySQLdb.connect(host="localhost", user="root", passwd="1234", db="mdb", )
dbc = db.cursor()
db.set_character_set('utf8')
dbc.execute("SET NAMES 'utf8';")
dbc.execute("SET SESSION collation_connection = 'utf8_general_ci';")
# Также пробовал
#dbc.execute('SET CHARACTER SET utf8;')
#dbc.execute('SET character_set_connection=utf8;')
#dbc.execute('SET collation_connection=utf8_general_ci;')
#dbc.execute('SET collation_database=utf8_general_ci;')
#dbc.execute('SET collation_server=utf8_general_ci;')
#dbc.execute('SET character_set_client=utf8;')
#dbc.execute('SET character_set_database=utf8;')
#dbc.execute('SET character_set_filesystem=utf8;')
#dbc.execute('SET character_set_results=utf8;')
#dbc.execute('SET character_set_server=utf8;')
text = "'Text текст'"
dbc.execute("insert into text values(%s);" % (text))
db.commit()
db.close()