In this case, the MySQLdb module in python returns utf8 or unicode encoding?

Using MySQLdb I connect to a database where everything is stored in utf8 encoding.

If i do

cursor.execute("SET NAMES utf8") 

and get some data from the database by another operator. Does this mean that the lines in

 cursor.execute("SELECT ...") cursor.fetchall() 

will be in unicode? Or do I need to turn them on first

 mystr.decode("utf8") 

in unicode?

+4
source share
1 answer

From documents :

connections (parameters ...)
...

use_unicode

If True, the CHAR and VARCHAR and TEXT columns are returned as Unicode strings using a customized character set. It is best to set the default encoding in the server configuration or client configuration (read using read_default_file). If you change the character set after connecting (MySQL-4.1 and later), you need to put the correct character set name in connection.charset.

If False, text columns are returned as regular rows, but you can always write Unicode rows.

This must be a keyword parameter.

+9
source

All Articles