In reading "High performance MySQL" from O'Reilly I've stumbled upon the following
Another common garbage query is SET
NAMES UTF8, which is the wrong way to
do things anyway (it does not change
the client library's character set; it
affects only the server).
As using this function results in a MySQL API call, it should be considered much faster than issuing a query.
In respect of performance the fastest way to ensure a UTF-8-based communiction between your script and the MySQL server is setting up the MySQL server correctly. As
SET NAMES x is equivalent to
SET character_set_client = x; SET character_set_results = x; SET character_set_connection = x;
SET character_set_connection = x internally also executes
SET collation_connection = <<default_collation_of_character_set_x>> you can also set these server variables statically in your
Please be aware of possible problems with other applications running on the same MySQL server instance and requiring some other character set.