character_set_connection的用途是什么? [英] What is the purpose of character_set_connection?

查看:717
本文介绍了character_set_connection的用途是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只要阅读Stefan Gehrig的精彩回答,即是SET CHARACTER SET utf8必要吗?,这比MySQL的文档在解释解释和运行查询w.r.t的阶段有点进一步。字符集和整理,但我仍然不能真正看到character_set_connection的目的,或更具体地将语句从character_set_client转换为character_set_connection。



为什么不使用character_set_client查询和转码直接从character_set_client到列的字符集与列值比较?这个中间阶段的目的是什么?手册给出了比较文字串的例子,但是为什么要这样做,更不用说在character_set_connection中反对character_set_client?除非我对这个的理解(像selectsomestr'='somestr'from x)是错误的。



谢谢。


在读取答案和文档之后,我只能想到 character_set_connection (和)的一个用例, code> _collat​​ion ):


SELECTStringA StringB


character_set_client 仅适用于传输到服务器。 character_set_connection (和排序规则不是独立于字符集)对于语句的解释是重要的。 StringA是否小于StringB取决于文字的字符集和排序规则。开发人员可能选择与 character_set_client 不同的字符集/排序规则。



实际上, character_set_connection 在大多数时候并不重要,因为字面量与列相比较,在这种情况下使用列的字符集和排序规则。





请参阅 https://dev.mysql.com/doc/refman/5.0/en/charset-connection.html


服务器将语句转换为
接收后的字符集应该是什么字符集?为此,服务器使用character_set_connection
和collat​​ion_connection系统变量。它将客户端从客户端发送的
语句从character_set_client转换为character_set_connection
(除了具有引导器的字符串文字,例如_latin1或
_utf8)。 collat​​ion_connection对于比较字符串很重要。对于字符串与列值的比较,
collat​​ion_connection并不重要,因为列有自己的
排序规则,其排序规则优先级较高。



Just read Stefan Gehrig excellent answer to Is "SET CHARACTER SET utf8" necessary?, which goes a bit further than MySQL's documentation at explaining the stages of interpretting and running a query w.r.t. character sets and collations, but I still can't really see the purpose of character_set_connection, or more specifically transcoding the statement from character_set_client into character_set_connection.

Why not just use character_set_client for the query and transcode straight from character_set_client to the character set of the column when comparing with column values? What is the purpose of this intermediate stage? The manual gives the example of comparing literal stings, but why would you want to do this in the first place, let alone in character_set_connection as oppose to character_set_client? Unless my understanding of this (something like "select 'somestr' = 'somestr' from x") is wrong.

Thank you.

解决方案

After reading the answers and documentation, I can only think of one use case for character_set_connection (and _collation):

SELECT "StringA" < "StringB"

character_set_client only matters for the transfer to the server. character_set_connection (and the collation, which is not independent from the character set) matters for the interpretation of the statement. Whether "StringA" is less than "StringB" depends on the character set and collation of the literals. A developer might choose a character set/collation which differs from character_set_client.

In practice, character_set_connection won't matter most of the time, because literals are compared to columns, in which case the column's charset and collation is used.

Correct me if I'm wrong!

See https://dev.mysql.com/doc/refman/5.0/en/charset-connection.html:

What character set should the server translate a statement to after receiving it? For this, the server uses the character_set_connection and collation_connection system variables. It converts statements sent by the client from character_set_client to character_set_connection (except for string literals that have an introducer such as _latin1 or _utf8). collation_connection is important for comparisons of literal strings. For comparisons of strings with column values, collation_connection does not matter because columns have their own collation, which has a higher collation precedence.

这篇关于character_set_connection的用途是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆