MySQL数据库编码概要(二)

2014-11-24 16:34:52 · 作者: · 浏览: 1
ing the character_set_server for server versions 4.1.0 and newer, and character_set system variable for server versions older than 4.1.0. The driver automatically uses the encoding specified by the server.
如果客户端连接时没有提供编码(连接串无characterEncoding),则服务端会使用character_set_server变量来作为客户端编码(4.1.0后)。

For example, to use 4-byte UTF-8 character sets with Connector/J, configure the MySQL server with character_set_server=utf8mb4, and leave characterEncoding out of the Connector/J connection string. Connector/J will then autodetect the UTF-8 setting.

客户端如何制定编码?
To override the automatically detected encoding on the client side, use the characterEncoding property in the URL used to connect to the server.

When a client connects to the server, it sends the name of the character set that it wants to use. The server uses the name to set the character_set_client, character_set_results, and character_set_connection system variables. In effect, the server performs a SET NAMES operation using the character set name.
客户端与服务端建立链接时,会发送客户端所希望使用的编码集。服务端会用这个编码集去初始化三个系统变量character_set_client, character_set_results, and character_set_connection。如执行了语句 SET NAMES XXX一般:
SET NAMES xx可以指定connection编码为xx:
character_set_connection,character_set_results,character_set_client 系统变量可修改;

SET NAMES 'charset_name' 这句SQL等同与执行下面3个语句:
SET character_set_client = charset_name;
SET character_set_results = charset_name;
SET character_set_connection = charset_name;

A SET CHARACTER SET charset_name 等同于执行下面3个语句:
SET character_set_client = charset_name;
SET character_set_results = charset_name;
SET collation_connection = @@collation_database;

参考

http://dev.mysql.com/doc/refman/5.5/en/charset.html