mysql varbinary 与 varchar

标签 mysql character collation

我们使用 varchar(255) 在 mysql 中存储“关键字”。我们面临一个问题,即 mysql 会忽略“=”中用于比较目的的所有尾随空格。它确实尊重“like”比较中的尾随空格,但它不允许我们在 varchar 列中存储带有和不带有尾随空格的相同单词(如果它上面有“UNIQUE”索引)。

因此,我们正在考虑改用 varbinary。当列值中有多字节字符时,有人能提出建议吗?

最佳答案

安多马尔

我们使用 5.0.5 版。所有 mysql 版本都忽略尾随空格进行比较。来自手册:

All MySQL collations are of type PADSPACE. This means that all CHAR and VARCHAR values in MySQL are compared without regard to any trailing spaces. This is true for all MySQL versions, and it makes no difference whether your version trims trailing spaces from VARCHAR values before storing them

此外,mysql 认为在索引中有/没有尾随空格的文本是重复的:

For those cases where trailing pad characters are stripped or comparisons ignore them, if a column has an index that requires unique values, inserting into the column values that differ only in number of trailing pad characters will result in a duplicate-key error. For example, if a table contains 'a', an attempt to store 'a ' causes a duplicate-key error.

而且,我们绝对需要关键字索引。 所以,我想我们有两个选择:varbinary 或 text。我们将评估“文本”的性能和 varbinary 的多字节功能。

关于mysql varbinary 与 varchar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22786418/

相关文章:

php - 使用 fputcsv 连接列

mysql - SQL - 如何为我的选择查询添加此自定义订单?

mysql - 在 mysql 中的 INSERT 查询中为 INT 类型列传递 ''(空),适用于某些配置,但不适用于其他配置

sql - Advantage 数据库、区分大小写和排序规则

mysql - UTF8_general_ci 排序规则需要几秒钟来处理

php - 尝试使用 beginTransaction() 和 commit() 但当我将命令放入时失败

c++ - 如何避免为 int 变量输入 char?

html - Chrome 不显示特殊字符,而其他浏览器显示

c++ - 从字符串中删除重复字符

sql - 排序规则冲突