﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
3151	"[patch] ""SET NAMES utf8"" is sent before every query"	smurf@…	Adrian Holovaty	"    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
}}}"	enhancement	closed	Database layer (models, ORM)	dev	minor	fixed	mysql	mir@… dev@…	Unreviewed	1	0	0	0	0	0
