Skip to content

Commit 7d4993a

Browse files
committed
Workaround for recommended MySQL 5.5 utf8mb4 character set, which is not recognized by Python yet.
1 parent f982ab4 commit 7d4993a

3 files changed

Lines changed: 8 additions & 4 deletions

File tree

MySQLdb/connections.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,10 @@ def set_character_set(self, charset):
289289
set can only be changed in MySQL-4.1 and newer. If you try
290290
to change the character set from the current value in an
291291
older version, NotSupportedError will be raised."""
292+
if charset == "utf8mb4":
293+
py_charset = "utf8"
294+
else:
295+
py_charset = charset
292296
if self.character_set_name() != charset:
293297
try:
294298
super(Connection, self).set_character_set(charset)
@@ -297,8 +301,8 @@ def set_character_set(self, charset):
297301
raise NotSupportedError("server is too old to set charset")
298302
self.query('SET NAMES %s' % charset)
299303
self.store_result()
300-
self.string_decoder.charset = charset
301-
self.unicode_literal.charset = charset
304+
self.string_decoder.charset = py_charset
305+
self.unicode_literal.charset = py_charset
302306

303307
def set_sql_mode(self, sql_mode):
304308
"""Set the connection sql_mode. See MySQL documentation for

tests/default.cnf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ host = 127.0.0.1
77
user = test
88
database = test
99
#password =
10-
default-character-set = utf8
10+
default-character-set = utf8mb4

tests/travis.cnf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ host = 127.0.0.1
77
user = root
88
database = mysqldb_test
99
#password =
10-
default-character-set = utf8
10+
default-character-set = utf8mb4

0 commit comments

Comments
 (0)