MySQL MySQL的ANSI和Unicode驱动的区别
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25889046/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Difference between ANSI and Unicode drivers of MySQL
提问by Malwinder Singh
On choosing Data Source under ODBC (64-Bit) on Windows, i get two available options of MySQL Database:
在 Windows 上选择 ODBC(64 位)下的数据源时,我得到 MySQL 数据库的两个可用选项:
- MySQL ODBC 5.3 ANSI Driver
- MySQL ODBC 5.3 Unicode Driver
- MySQL ODBC 5.3 ANSI 驱动程序
- MySQL ODBC 5.3 Unicode 驱动程序
What are the difference between these two?
这两者有什么区别?
采纳答案by bohica
Firstly I should say that I don't use MySQL but I do know about ODBC Drivers. In ODBC there are different APIs for unicode and ansi. The ansi APIs end in A and the unicode APIs end in W (e.g., SQLPrepareA and SQLPrepareW). The ansi APIs accept bytes/octets for character strings and hence can only handle chrs 0-255. The unicode APIs accept SQLWCHARs which are 2 byte UCS-2 encoded unicode codepoints (newer MS SQL Server versions can handle UTF16 encoded strings) and so can handle approximately the first 65000 codepoints in unicode.
首先我应该说我不使用 MySQL,但我知道 ODBC 驱动程序。在 ODBC 中,unicode 和 ansi 有不同的 API。ansi API 以 A 结尾,unicode API 以 W 结尾(例如,SQLPrepareA 和 SQLPrepareW)。ansi API 接受字符串的字节/八位字节,因此只能处理 0-255 字符。unicode API 接受 SQLWCHAR,它们是 2 字节 UCS-2 编码的 unicode 代码点(较新的 MS SQL Server 版本可以处理 UTF16 编码的字符串),因此可以处理大约前 65000 个 unicode 代码点。
So if you need to store unicode data you have no choice which driver to use.
因此,如果您需要存储 unicode 数据,您将无法选择使用哪个驱动程序。
I would not let the comments on speed from Carnangel put you off using the unicode driver and in any case his comments do not include any facts. He may be referring to:
我不会让 Carnangel 对速度的评论使您对使用 unicode 驱动程序望而却步,无论如何,他的评论不包含任何事实。他可能指的是:
If you store unicode data in MySQL it will be UTF-8 encoded and transferred over your network as UTF-8. At the client end the ODBC driver will have to convert the UTF-8 encoded data into UCS-2 as this is what ODBC needs. Obviously the reverse applies.
如果您在 MySQL 中存储 unicode 数据,它将被 UTF-8 编码并作为 UTF-8 通过您的网络传输。在客户端,ODBC 驱动程序必须将 UTF-8 编码数据转换为 UCS-2,因为这是 ODBC 所需要的。显然,反之亦然。
If you write an ANSI ODBC application (that is one which uses the ansi ODBC apis) with a unicode ODBC driver then the ODBC Driver manager will have to convert the UCS-2 the driver returns to 8 bit (lossy) and convert the 8 bit data you pass to the driver to UCS-2. So don't do that.
如果您使用 Unicode ODBC 驱动程序编写 ANSI ODBC 应用程序(即使用 ansi ODBC apis 的应用程序),则 ODBC 驱动程序管理器必须将 UCS-2 驱动程序返回到 8 位(有损)并转换 8 位您传递给驱动程序的数据到 UCS-2。所以不要那样做。
These days I'd be surprised if anyone is still using ANSI ODBC drivers.
现在,如果有人仍在使用 ANSI ODBC 驱动程序,我会感到惊讶。
回答by Carnangel
As you may know Ansi and unicode are applied to the data character type. You can choose one or the other, it is not a question of processor Here is the difference between them: - Unicode allow you to have all the characters properties enabled but reducing raw speed treatment - Ansi, the opposite, less character type but raw speed treatement will speed up
您可能知道 Ansi 和 unicode 应用于数据字符类型。您可以选择一个或另一个,这不是处理器的问题这是它们之间的区别: - Unicode 允许您启用所有字符属性,但减少原始速度处理 - Ansi,相反,较少字符类型但原始速度治疗会加速
If you are a new user take the Unicode one, if not you can choose the Ansi one.
如果您是新用户,请选择 Unicode 一个,如果不是,您可以选择 Ansi 一个。
I hope you've got the point ;)
我希望你明白这一点;)