[patch] "SET NAMES utf8" is sent before every query
    
    
    
      
      
      
        
No, we do not need to send a "SET NAMES utf8" to the server before every
mysql request. Just before the first one.
Depending on the latency of your database connection and/or the prevalence of cached queries,
this change may significantly reduce your response time.
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
index e7e060e..28c5b1c 100644
--- a/django/db/backends/mysql/base.py
+++ b/django/db/backends/mysql/base.py
@@ -98,9 +98,11 @@ class DatabaseWrapper(local):
                 kwargs['port'] = int(settings.DATABASE_PORT)
             kwargs.update(self.options)
             self.connection = Database.connect(**kwargs)
-        cursor = self.connection.cursor()
-        if self.connection.get_server_info() >= '4.1':
-            cursor.execute("SET NAMES 'utf8'")
+            cursor = self.connection.cursor()
+            if self.connection.get_server_info() >= '4.1':
+                cursor.execute("SET NAMES 'utf8'")
+        else:
+            cursor = self.connection.cursor()
         if settings.DEBUG:
             return util.CursorDebugWrapper(MysqlDebugWrapper(cursor), self)
         return cursor
       
     
   
Passes all tests using the mysql backend at r4227.