Answer the question
In order to leave comments, you need to log in
Russian character encoding (Mysql5.5+python3.4)?
Problem. When adding Russian letters to the database, the data is displayed incorrectly (in the wrong encoding).
If you add data from the Mysql console, everything is fine.
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()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question