0

Before I begin, I know this question is highly asked, but i've viewed nearly every SO question that fits various search terms relating to this issue.

My issue is that I am trying to store a 3 Byte character in utf8, not 4 bytes as many questions ask, specifically chinese characters.

DB character set is utf8 with utf8_general_ci collation. The column, table, and connection char sets are also utf8.

MySQLdb.connect(host, user, passwd, schema, charset ='utf8', use_unicode=True)

I know use_unicode is implied, but I like the verbosity.

The warning I'm getting is: Warning: Incorrect string value: '\xE5\x9B\xBD' for column 'mycolumn' at row 1

This results in SELECTS of that field, resulting in a ?. My terminal supports utf8, as well as my system encoding being utf8.

Any ideas would help. Calling .decode('utf8') on this value also does not solve the issue.

1 Answer 1

1

Turns out this ended up being a problem with a stored procedure. From the MYSQL docs.

If CHARACTER SET and COLLATE attributes are not present, the database character set and collation in effect at routine creation time are used. To avoid having the server use the database character set and collation, provide explicit CHARACTER SET and COLLATE attributes for character data parameters.

The connection and client encoding was UTF8, however the DB still remained as latin1. This was causing issues because the stored procedure was created when the DB encoding was latin1.

TLDR; Add CHARSET utf8 to your stored procedure parameters.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.