将mysql中的* everything *更改为utf8

时间:2012-12-04 20:47:55

标签: mysql character-encoding

  

可能重复:
  UTF-8 all the way through

我在将数据库中的所有内容更改为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     |       |
+---------------+-------+

1 个答案:

答案 0 :(得分:1)

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

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

[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/ |
+--------------------------+----------------------------+