MySQL 更改服务器变量 character_set_server

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

Change server variable character_set_server

mysqlcharacter-encoding

提问by grai

I want to change the mysql server variable character_set_serverto utf8. I have googled on this but can't seem to find the information I'm looking for or the instructions don't match. It seems I need to edit a file called my.cnf but this file does not exist on my system. The version is 5.1.36.

我想将mysql服务器变量更改character_set_server为utf8。我已经在谷歌上搜索过,但似乎无法找到我正在寻找的信息或说明不匹配。看来我需要编辑一个名为 my.cnf 的文件,但我的系统上不存在该文件。版本是 5.1.36。

采纳答案by Nicola Cossu

Run this query:

运行此查询:

set global character_set_server = utf8;

then restart mysql. you can see the list of all your variables with a simple

然后重启mysql。您可以使用简单的命令查看所有变量的列表

show variables;

回答by ajreal

this is first result from google

这是谷歌的第一个结果

http://dev.mysql.com/doc/refman/5.0/en/server-options.html#option_mysqld_character-set-server

http://dev.mysql.com/doc/refman/5.0/en/server-options.html#option_mysqld_character-set-server

there are two ways to set this configuration

有两种方法可以设置此配置

  • via configuration file (character-set-server), required restart
  • or via set global/sessioncharacter_set_server, this does not require restart, BUT if your database restarted, it will gone, then you will need to set this again
  • 通过配置文件(字符集服务器),需要重启
  • 或者通过set global/sessioncharacter_set_server,这不需要重启,但是如果你的数据库重启了,它就会消失,那么你需要再次设置

回答by Paul Gobée

Locations of the my.ini and my.cnf files:

my.ini 和 my.cnf 文件的位置:

http://dev.mysql.com/doc/refman/5.0/en/option-files.html

http://dev.mysql.com/doc/refman/5.0/en/option-files.html

As to the question whether you should use my.ini or my.cnffiles, the above documentation states that

至于你应该使用my.ini 还是 my.cnf文件的问题,上面的文档指出

Windows systems use both my.ini and my.cnf,

Windows 系统同时使用 my.ini 和 my.cnf,

Linux, Unix, Mac OS X systems use my.cnf.

Linux、Unix、Mac OS X 系统使用 my.cnf。