MySQL排序规则:latin1_swedish_ci Vs utf8_general_ci [英] MySQL Collation: latin1_swedish_ci Vs utf8_general_ci
问题描述
我一直在使用latin1_swedish_ci - 会不会有任何问题?
CREATE TABLE IF NOT EXISTS`db`.`events_user_preference`
`user_id` INT(10)UNSIGNED NOT NULL,
`email` VARCHAR(40)NULL DEFAULT NULL,
PRIMARY KEY(`user_id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = latin1_swedish_ci
而@Blaisorblade指出解决这个问题的方法是使用与瑞典排序规则一起使用的字符集:
DEFAULT CHARACTER SET = utf8_swedish_ci
Yii php框架的cal(日历)模块的SQL与上述错误代码类似。希望他们现在已经修复了。
What should I set for Collation when creating tables in MySQ - latin1_swedish_ci or utf8_general_ci? What is Collation anyway?
I have been using latin1_swedish_ci - would it cause any problems?
Whatever you do, don't try to use the default swedish_ci collation with utf8 (instead of latin) in mysql, or you'll get an error. Collations must be paired with the right charset to work. This SQL will fail because of the mismatch in charset and collation:
CREATE TABLE IF NOT EXISTS `db`.`events_user_preference` (
`user_id` INT(10) UNSIGNED NOT NULL ,
`email` VARCHAR(40) NULL DEFAULT NULL ,
PRIMARY KEY (`user_id`) )
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = latin1_swedish_ci
And @Blaisorblade pointed out that the way to fix this is to use the character set that goes with the swedish collation:
DEFAULT CHARACTER SET = utf8_swedish_ci
The SQL for the cal (calendar) module for the Yii php framework had something similar to the above erroneous code. Hopefully they've fixed it by now.
这篇关于MySQL排序规则:latin1_swedish_ci Vs utf8_general_ci的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!