1

可能重复:
一直到 UTF-8

我在将数据库中的所有内容更改为 utf8 时遇到了一些困难。

这是我目前拥有的:

+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | latin1                     |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
| collation_connection     | utf8_general_ci            |
| collation_database       | latin1_swedish_ci          |
| collation_server         | latin1_swedish_ci          |
+--------------------------+----------------------------+

我有一个/etc/my.cnf包含以下内容的文件:

[client]
default-character-set=utf8

[mysql]
default-character-set=utf8


[mysqld]
init_connect='SET collation_connection = utf8_general_ci'
init_connect='SET NAMES utf8'
default-character-set=utf8
character-set-server=utf8
collation-server=utf8_general_ci
skip-character-set-client-handshake

当我$ sudo service mysql restart“加载”文件时,什么也没有发生。我怎样才能得到utf8这里的一切?

mysql> show variables like '%init_file%';
+---------------+-------+
| Variable_name | Value | 
+---------------+-------+
| init_file     |       |
+---------------+-------+
4

1 回答 1

1

我认为您的问题在于您使用的是破折号而不是下划线。我认为破折号用于命令行选项,而这些用于my.cnf. 是的,这真是令人困惑!

我本地 Ubuntu 中唯一的 utf8 引用my.cnf是:

[mysqld]
...
character_set_server = utf8         # you have character-set-server
collation_server = utf8_general_ci  # you have collation-server

我的任何变量看起来像:

mysql> show variables like '%charac%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8                       |
| character_set_connection | utf8                       |
| character_set_database   | utf8                       |
| character_set_filesystem | binary                     |
| character_set_results    | utf8                       |
| character_set_server     | utf8                       |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
于 2012-12-04T22:43:46.810 回答