Bug #80594 Messy Codes happens while using Python 2.x insert Chinese character UTF-8
Submitted: 3 Mar 2016 3:16 Modified: 3 Mar 2016 7:47
Reporter: Tiger King King Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / Python Severity:S1 (Critical)
Version:5.7 OS:Windows (Microsoft Windows 7 Ultimate Service Pack 1)
Assigned to: CPU Architecture:Any
Tags: WBBugReporter

[3 Mar 2016 3:16] Tiger King King
Description:
----[For better reports, please attach the log file after submitting. You can find it in C:\Users\Tiger\AppData\Roaming\MySQL\Workbench\log\wb.log]

using python 2.7 , MySQLdb to insert values into mysql. before inserting, coding is UTF-8, but using MySQL WorkBenck to query, messy codes of Chinese characters happens. 

However, I use python, MySQLdb to select some data from mysql, it's normal.the example in the following:
sql = "select * from user_profile where user_id= 'b6f247e7112f4bf0a5a66ffdbf89d29e'"
cursor.execute(sql)
I get:
('b6f247e7112f4bf0a5a66ffdbf89d29e', '\xe5\x90\x89\xe8\xb7\xaf', 'male', '\xe6\x88\x91\xe7\x88\xb1\xe6\xa0\x91\xe6\x9c\xa8', '', '\xe7\x94\x9f\xe7\x89\xa9\xe5\xb7\xa5\xe7\xa8\x8b', '', '', '', '', 'description', 0L, 71L, 0L, 21L, 166L, 0L, 20L, 28L')

print('\xe8\x90\x8c\xe8\x99\xab')
print('\xe6\x88\x91\xe7\x88\xb1\xe6\xa0\x91\xe6\x9c\xa8')
print('\xe7\x94\x9f\xe7\x89\xa9\xe5\xb7\xa5\xe7\xa8\x8b')

I get:
萌虫
我爱树木
生物工程

however:
print(u'\xe8\x90\x8c\xe8\x99\xab')
print(u'\xe6\x88\x91\xe7\x88\xb1\xe6\xa0\x91\xe6\x9c\xa8')
print(u'\xe7\x94\x9f\xe7\x89\xa9\xe5\xb7\xa5\xe7\xa8\x8b')

萌虫
我爱树木
生物工程

name = '\xe8\x90\x8c\xe8\x99\xab'
name2 = '萌虫'
print(name2==name)
True

How to repeat:
Mess codes like:

'b6f247e7112f4bf0a5a66ffdbf89d29e', '吉路', 'male', '我爱树木', '', '生物工程', '', '', '', '', 'description', '0', '71', '0', '21', '166', '0', '20', '28''

while in python:
吉路萌虫 
我爱树木我爱树木 
生物工程生物工程

Suggested fix:
I using pycharm 5.0 to develop, the file encoding is utf-8, and has
# -*- coding: UTF-8 -*-
in my.ini of mysql, mysql and mysqldb is also set default utf-8:
[mysql]
default-character-set=utf8
[mysqld]
default-character-set=utf8

in creating table also set character setting default utf-8:
CREATE TABLE IF NOT EXISTS `xxx`.`user_profile` (
  `user_id` varchar(50) NOT NULL,
  `name` VARCHAR(30) CHARACTER SET 'utf8' NULL,
  `gender` VARCHAR(10) CHARACTER SET 'utf8' NULL,
  `short_desc` VARCHAR(45) CHARACTER SET 'utf8' NULL,
  `location` VARCHAR(45) CHARACTER SET 'utf8' NULL,
  
  `industry` VARCHAR(60) CHARACTER SET 'utf8' NULL,
  `company` varchar(30) CHARACTER SET 'utf8' NULL,
  `job` VARCHAR(45) CHARACTER SET 'utf8' NULL,
  `school` VARCHAR(100) CHARACTER SET 'utf8' NULL,
  `major` VARCHAR(100) NULL,
  
   
  PRIMARY KEY (`user_id`)) DEFAULT CHARACTER SET = 'utf8' COLLATE utf8_general_ci 
ENGINE = InnoDB
[3 Mar 2016 7:47] Chiranjeevi Battula
Hello Tiger King King,

Thank you for the bug report.
I tried to reproduce the issue at my end using Python 2.7.10 , MySQL 5.7.11, PyCharm 5.0.4 and Connector 2.1.3 but not seeing any issues in insert and select Chinese character.
And moreover MySQLdb is not related to MySQL Connector/Python.

Thanks,
Chiranjeevi.
[3 Mar 2016 7:47] Chiranjeevi Battula
Screenshot.

Attachment: 80594.PNG (image/png, text), 111.85 KiB.