Mysql 更改信息模式的列排序规则和字符集

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/979656/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 13:27:38  来源:igfitidea点击:

Mysql change column collation and character set of information schema

mysqldatabasesystemcollation

提问by MySQL DBA

I want to change column collation and character set of system database information_schema...

我想更改系统数据库information_schema的列排序规则和字符集...

Can anyone give any input on how to do this? Is there any special priviledges i need for this

任何人都可以就如何做到这一点提供任何意见吗?我需要什么特殊的特权吗

采纳答案by Chris Vest

As far as I know, you cannot run ALTER TABLEcommands on the tables in information_schema. Instead you will probably want to take a look at the character_set_*variabes. You can see which variables are set to which values in your MySQL server with a show variablescommand:

据我所知,您不能ALTER TABLEinformation_schema. 相反,您可能想要查看character_set_*变量。您可以使用以下show variables命令查看 MySQL 服务器中哪些变量设置为哪些值:

show variables like "character_set_%";

The variable that has to do with meta data in MySQL, such as the information_schematables, is the character_set_systemvariable. I think the my.cnfis the right place to set it.

与 MySQL 中的元数据(例如information_schema表)有关的character_set_system变量是变量。我认为这my.cnf是设置它的正确位置。

There's more information on this page: UTF-8 for Metadata.

此页面上有更多信息:UTF-8 for Metadata

For ordinary tables, you change the character set of a table with an ALTER TABLEcommand:

对于普通表,您可以使用以下ALTER TABLE命令更改表的字符集:

alter table some_table convert to character set utf8;

To do this, you will need the "alter" privilege.

为此,您将需要“更改”权限。

You can see which privileges your MySQL server supports with a show privilegescommand, and you can see which privileges are granted to your current user with a show grantscommand.

您可以使用show privileges命令查看您的 MySQL 服务器支持哪些权限,您可以使用命令查看授予当前用户哪些权限show grants

回答by Haim Evgi

To change the character set and collation for all columns in an existing table, use:

要更改现有表中所有列的字符集和排序规则,请使用:

ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name [COLLATE collation_name];

回答by Rutamation

alter table some_table convert to character set utf8;

awesome that worked great as far as i can tell for me, now i can use chinese in that tables!! and i can remove all the utf8_encode() utf8_decode() throughout my site!

真棒,据我所知,效果很好,现在我可以在那个表中使用中文了!!我可以删除整个站点中的所有 utf8_encode() utf8_decode() !