MySQL排序规则:latin1_swedish_ci Vs utf8_general_ci [英] MySQL Collation: latin1_swedish_ci Vs utf8_general_ci

查看:1393
本文介绍了MySQL排序规则:latin1_swedish_ci Vs utf8_general_ci的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MySQ中创建表时,我应该为排序规则设置什么 - latin1_swedish_ci或utf8_general_ci?什么是排序规则?



我一直在使用latin1_swedish_ci - 会不会有任何问题?

解决方案无论你做什么,不要尝试在mysql中使用utf8(而不是latin)的默认的swedish_ci排序规则,否则你会收到一个错误。排序必须与正确的字符集配对才能工作。由于字符集和排序规则不匹配,此SQL将失败:

  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屋!

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