SET NAMES

High Performance MySQL, Third Editionby Baron Schwartz, Peter Zaitsev, and Vadim Tkachenko

Settings for client/server communication When the server and the client communicate with each other, they might send data back and forth in different character sets. The server will translate as needed:

• The server assumes the client is sending statements in the character set specifiedby character_set_client.

• After the server receives a statement from the client, it translates it into the characterset specified by character_set_connection. It also uses this setting to determinehow to convert numbers into strings.

• When the server returns results or error messages back to the client, it translatesthem into character_set_result.

Suppose you open a client connection with latin1 (the default character set, unless you’ve used mysql_options() to change it) and then use SET NAMES utf8 to tell the serverto assume the client is sending data in UTF-8. You’ve created a character set mismatch,which can cause errors and even security problems.

原文地址:https://www.cnblogs.com/rsapaper/p/5838445.html