MySQL 如何设置默认字符集?

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

How to set the default character-set?

mysql

提问by kaiwii ho

I want to create a new db in mysql. I set utf8 as the default-character-set, but when I attempted to restart the db, mysql failed to restart and posted the following prompt:

我想在 mysql 中创建一个新的数据库。我将 utf8 设置为默认字符集,但是当我尝试重新启动数据库时,mysql 无法重新启动并发布以下提示:

Trying to start the server ... Could not re-connect to the MySQL Server. Server could not be started.

正在尝试启动服务器...无法重新连接到 MySQL 服务器。服务器无法启动。

Plugin 'FEDERATED' is disabled.

插件“联邦”被禁用。

C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld: unknown variable 'default-character-set=utf8'

C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld: 未知变量 'default-character-set=utf8'

Aborting

中止

C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld: Shutdown complete

C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqld:关闭完成

I know that after cancelling the default-character-set, mysql will restart. But if I hadto set the default-character-set, is there some other way to make mysql work again?

我知道取消default-character-set后,mysql会重启。但是如果我必须设置默认字符集,还有其他方法可以让 mysql 再次工作吗?

回答by robguinness

I had a similar problem. The answer, as EO2 pointed out, is that default-character-set is deprecated in 5.5. You should use instead:

我有一个类似的问题。正如 EO2 所指出的,答案是默认字符集在 5.5 中已被弃用。你应该使用:

character-set-server = utf8

BTW, it's better if answers are answered as answers, not comments... ;-)

顺便说一句,如果答案作为答案而不是评论来回答会更好...... ;-)

回答by Omar Ahmed

I had a similar problem when running mysqlslap i get the following error:

我在运行 mysqlslap 时遇到了类似的问题,出现以下错误:

mysqlslap unknown variable 'default-character-set=utf8mb4'

After a lot of investigations i discovered that default-character-setwas being set in another file instead of all the config files i changed.

经过大量调查后,我发现它default-character-set被设置在另一个文件中,而不是我更改的所有配置文件中。

The option was set in /etc/mysql/mariadb.conf.d/50-client.cnf, so i just commented this line default-character-set = utf8mb4and everything went well.

该选项设置在 中/etc/mysql/mariadb.conf.d/50-client.cnf,所以我只是评论了这一行default-character-set = utf8mb4,一切都很顺利。

I have MySQL running on Debian 9. that in case someone is having the same problem.

我在 Debian 9 上运行 MySQL。以防万一有人遇到同样的问题。