如何更改MySQL列的排序规则类型? [英] How do you change the collation type for a MySQL column?

查看:237
本文介绍了如何更改MySQL列的排序规则类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有utf-8 Vs.这里提到的字节串问题: Django头痛与简单的非ascii字符串



我不在乎MySQL列中的区分大小写匹配,我只是总是想要返回UTF-8字符串,因为我发现不可能处理返回的字符串对于非ascii文本的字符列。



如何更改我的MySQL排序规则类型,以便始终通过Django返回UTF-8字符串?

解决方案

您需要注意数据库/表/列级别的字符集/排序规则设置。列级设置优先于其他设置。因此,我包括可用于在db的每个级别执行这些更改的命令。






检查您当前的配置(数据库):



SHOW CREATE DATABASE db_name;



检查您当前的配置(表):



SHOW TABLE STATUS WHERE name ='tbl_name'



检查您当前的配置(列):



SHOW FULL COLUMNS FROM tbl_name;






更改character-set / collat​​ion(数据库):



ALTER DATABASE db_name DEFAULT CHARACTER SET utf8;



更改字符集/ collat​​ion(table):



ALTER TABLE tbl_name DEFAULT CHARACTER SET utf8;



更改字符集/排序规则(列):



ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8; code>


I'm having the utf-8 Vs. byte string problems mentioned here: Django headache with simple non-ascii string

I don't care about case sensitive matching in the MySQL columns, I just always want UTF-8 strings returned because I find it is impossible to deal with byte strings returned for character columns for non-ascii text.

How do I change my MySQL collation type so that UTF-8 strings are always returned through Django?

解决方案

You need to be aware of the character-set/collation settings at the database/table/column levels. Column-level settings take precedence over the others. Because of this, I'm including commands you can use to perform these changes at each level of the db.


Inspect your current configuration (database):

SHOW CREATE DATABASE db_name;

Inspect your current configuration (table):

SHOW TABLE STATUS WHERE name='tbl_name'

Inspect your current configuration (columns):

SHOW FULL COLUMNS FROM tbl_name;


Change the character-set/collation (database):

ALTER DATABASE db_name DEFAULT CHARACTER SET utf8;

Change the character-set/collation (table):

ALTER TABLE tbl_name DEFAULT CHARACTER SET utf8;

Change the character-set/collation (columns):

ALTER TABLE tbl_name CONVERT TO CHARACTER SET utf8;

这篇关于如何更改MySQL列的排序规则类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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