Always decode at the input and encode at the output. (To do this, it should be useful to me: perhaps, “remove your code [coat] when you arrive indoors.”)
Input decoding: you say the encoding of the database is "UTF_8_bin". Do you use MySQL-Python ? If so, you can set the use_unicode parameter when connecting to the database. Then all the rows are retrieved from the Unicode database, so you don’t have to worry about decrypting them.
Encode on output: you can find out the current character encoding (or code page "as they call it on Windows) using chcp . Suppose code page 1252. Then you can write
print text.encode('windows-1252')
to create something you can read from the windows command prompt.
If you write rows back to another MySQL database using MySQL-Python, you don’t need to do anything special: MySQL-Python states that you can always write Unicode strings (regardless of whether you use_unicode when you opened compound).
source share