Yog*_*oga 12 mysql percona character-set mysql-5.5 utf-8
我正在使用 MySQL 5.5,当我显示有关字符集的变量时,我有
+--------------------------+----------------------------+
| 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/ |
+--------------------------+----------------------------+
Run Code Online (Sandbox Code Playgroud)
我是否需要将character_set_database
和更改character_set_server
为utf8
?
想想看:
latin1
latin1
如果来自操作系统或连接的数据是utf8
,mysqld 将如何处理它?
您可以更改传入的字符集行为,而不是猜测或希望得到最好的结果。除了information_schema
and mysql
,获取所有数据库并将默认字符集设置为utf8
:
ALTER DATABASE dbname CHARACTER SET utf8;
Run Code Online (Sandbox Code Playgroud)
如果您有特定的排序规则,请执行以下操作:
ALTER DATABASE dbname COLLATE 'utf8_general_ci';
Run Code Online (Sandbox Code Playgroud)
以下是可供选择的排序规则:
mysql> select * from information_schema.collations where CHARACTER_SET_NAME = 'utf8';
+--------------------+--------------------+-----+------------+-------------+---------+
| COLLATION_NAME | CHARACTER_SET_NAME | ID | IS_DEFAULT | IS_COMPILED | SORTLEN |
+--------------------+--------------------+-----+------------+-------------+---------+
| utf8_general_ci | utf8 | 33 | Yes | Yes | 1 |
| utf8_bin | utf8 | 83 | | Yes | 1 |
| utf8_unicode_ci | utf8 | 192 | | Yes | 8 |
| utf8_icelandic_ci | utf8 | 193 | | Yes | 8 |
| utf8_latvian_ci | utf8 | 194 | | Yes | 8 |
| utf8_romanian_ci | utf8 | 195 | | Yes | 8 |
| utf8_slovenian_ci | utf8 | 196 | | Yes | 8 |
| utf8_polish_ci | utf8 | 197 | | Yes | 8 |
| utf8_estonian_ci | utf8 | 198 | | Yes | 8 |
| utf8_spanish_ci | utf8 | 199 | | Yes | 8 |
| utf8_swedish_ci | utf8 | 200 | | Yes | 8 |
| utf8_turkish_ci | utf8 | 201 | | Yes | 8 |
| utf8_czech_ci | utf8 | 202 | | Yes | 8 |
| utf8_danish_ci | utf8 | 203 | | Yes | 8 |
| utf8_lithuanian_ci | utf8 | 204 | | Yes | 8 |
| utf8_slovak_ci | utf8 | 205 | | Yes | 8 |
| utf8_spanish2_ci | utf8 | 206 | | Yes | 8 |
| utf8_roman_ci | utf8 | 207 | | Yes | 8 |
| utf8_persian_ci | utf8 | 208 | | Yes | 8 |
| utf8_esperanto_ci | utf8 | 209 | | Yes | 8 |
| utf8_hungarian_ci | utf8 | 210 | | Yes | 8 |
| utf8_sinhala_ci | utf8 | 211 | | Yes | 8 |
+--------------------+--------------------+-----+------------+-------------+---------+
22 rows in set (0.03 sec)
Run Code Online (Sandbox Code Playgroud)
你也可以跑
mysql> show collation where charset='utf8';
+--------------------+---------+-----+---------+----------+---------+
| Collation | Charset | Id | Default | Compiled | Sortlen |
+--------------------+---------+-----+---------+----------+---------+
| utf8_general_ci | utf8 | 33 | Yes | Yes | 1 |
| utf8_bin | utf8 | 83 | | Yes | 1 |
| utf8_unicode_ci | utf8 | 192 | | Yes | 8 |
| utf8_icelandic_ci | utf8 | 193 | | Yes | 8 |
| utf8_latvian_ci | utf8 | 194 | | Yes | 8 |
| utf8_romanian_ci | utf8 | 195 | | Yes | 8 |
| utf8_slovenian_ci | utf8 | 196 | | Yes | 8 |
| utf8_polish_ci | utf8 | 197 | | Yes | 8 |
| utf8_estonian_ci | utf8 | 198 | | Yes | 8 |
| utf8_spanish_ci | utf8 | 199 | | Yes | 8 |
| utf8_swedish_ci | utf8 | 200 | | Yes | 8 |
| utf8_turkish_ci | utf8 | 201 | | Yes | 8 |
| utf8_czech_ci | utf8 | 202 | | Yes | 8 |
| utf8_danish_ci | utf8 | 203 | | Yes | 8 |
| utf8_lithuanian_ci | utf8 | 204 | | Yes | 8 |
| utf8_slovak_ci | utf8 | 205 | | Yes | 8 |
| utf8_spanish2_ci | utf8 | 206 | | Yes | 8 |
| utf8_roman_ci | utf8 | 207 | | Yes | 8 |
| utf8_persian_ci | utf8 | 208 | | Yes | 8 |
| utf8_esperanto_ci | utf8 | 209 | | Yes | 8 |
| utf8_hungarian_ci | utf8 | 210 | | Yes | 8 |
| utf8_sinhala_ci | utf8 | 211 | | Yes | 8 |
+--------------------+---------+-----+---------+----------+---------+
22 rows in set (0.00 sec)
mysql>
Run Code Online (Sandbox Code Playgroud)
要查看数据库的单个字符集,请运行:
mysql> show create database sample;
+----------+-------------------------------------------------------------------+
| Database | Create Database |
+----------+-------------------------------------------------------------------+
| sample | CREATE DATABASE `sample` /*!40100 DEFAULT CHARACTER SET latin1 */ |
+----------+-------------------------------------------------------------------+
1 row in set (0.00 sec)
mysql>
Run Code Online (Sandbox Code Playgroud)
至于设置,你可以试试这个:
将行添加到 my.cnf
[mysqld]
character_set_database=utf8
character_set_server=utf8
Run Code Online (Sandbox Code Playgroud)
然后重启mysql
我在 2011 年 8 月 1 日讨论了这个:表格中的字符集编码
这些命令
ALTER DATABASE dbname CHARACTER SET utf8;
ALTER DATABASE dbname COLLATE 'utf8_general_ci';
Run Code Online (Sandbox Code Playgroud)
由于 Windows 锁定文件的方式,在 Windows 版本的 MySQL 中不起作用。调用所需的文件,该文件db.opt
位于datadir
.
您可能必须执行以下操作:
不管你做什么,请在 Dev/Staging Server 上执行任何更改,看看是否获得了预期的效果
你的问题
我真的应该改变它吗?
为保证数据得到正确处理,您可能需要确保您有一对一的关系。数据准备为一个字符集并将其加载到与数据库的表中,可能会对齐数据,就好像它看到另一个字符集一样,mysqld 在检索并发送回数据库连接时可能不会显示具有字符集的数据。尝试在 Dev/Staging Server 上加载数据库并尝试设置默认字符集。
为什么有些默认使用
utf8
但有些默认使用latin1
?
这取决于 MySQL 二进制文件的操作系统版本。Windows 版本可能有,latin1
而 Linux 版本可能使用utf8
.
归档时间: |
|
查看次数: |
46337 次 |
最近记录: |