【问题标题】:MariaDB character set and collation on windows vs freeBSDWindows 与 freeBSD 上的 MariaDB 字符集和排序规则
【发布时间】:2018-02-06 10:48:55
【问题描述】:

我在追查为什么我的 Windows 开发安装的 MariaDB 与我的 FreeBSD 安装不匹配时遇到了一些麻烦。这是我在 freeBSD 上的测试数据库的一些输出:

MariaDB [www]> SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
+--------------------------+--------------------+
| Variable_name            | Value              |
+--------------------------+--------------------+
| character_set_client     | latin1             |
| character_set_connection | latin1             |
| character_set_database   | utf8mb4            |
| character_set_filesystem | binary             |
| character_set_results    | latin1             |
| character_set_server     | latin1             |
| character_set_system     | utf8               |
| collation_connection     | latin1_swedish_ci  |
| collation_database       | utf8mb4_unicode_ci |
| collation_server         | latin1_swedish_ci  |
+--------------------------+--------------------+
10 rows in set (0.00 sec)

MariaDB [www]> SHOW FULL COLUMNS FROM items;
+-------------+--------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
| Field       | Type         | Collation          | Null | Key | Default | Extra          | Privileges                      | Comment |
+-------------+--------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
| id          | int(11)      | NULL               | NO   | PRI | NULL    | auto_increment | select,insert,update,references |         |
| description | varchar(255) | utf8mb4_unicode_ci | YES  |     | NULL    |                | select,insert,update,references |         |
+-------------+--------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
2 rows in set (0.01 sec)

MariaDB [www]> select description from items where id=15;
+------------------------+
| description            |
+------------------------+
| 15 kΩ  1/8W 1%  (smd) |
+------------------------+
1 row in set (0.00 sec)

这是 Windows 上的等价物:

MariaDB [www]> SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
+--------------------------+--------------------+
| Variable_name            | Value              |
+--------------------------+--------------------+
| character_set_client     | latin1             |
| character_set_connection | latin1             |
| character_set_database   | utf8mb4            |
| character_set_filesystem | binary             |
| character_set_results    | latin1             |
| character_set_server     | latin1             |
| character_set_system     | utf8               |
| collation_connection     | latin1_swedish_ci  |
| collation_database       | utf8mb4_unicode_ci |
| collation_server         | latin1_swedish_ci  |
+--------------------------+--------------------+
10 rows in set (0.01 sec)
MariaDB [www]> SHOW FULL COLUMNS FROM items;
+-------------+--------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
| Field       | Type         | Collation          | Null | Key | Default | Extra          | Privileges                      | Comment |
+-------------+--------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
| id          | int(11)      | NULL               | NO   | PRI | NULL    | auto_increment | select,insert,update,references |         |
| description | varchar(255) | utf8mb4_unicode_ci | YES  |     | NULL    |                | select,insert,update,references |         |
+-------------+--------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+
2 rows in set (0.01 sec)

MariaDB [www]> select description from items where id=15;
+------------------------+
| description            |
+------------------------+
| 15 kΩ  1/8W 1%  (smd) |
+------------------------+
1 row in set (0.00 sec)

所以我的问题是,我在设置比较方面缺少什么,这可能是 Windows 上损坏字符 (Ω) 的来源,以及需要将其更改为什么才能获得相同的字符我的 FreeBSD 服务器。 FreeBSD 安装比 10.1.19-MariaDB mariadb.org 二进制分发版 10.1.23-MariaDB FreeBSD Ports 稍新。

【问题讨论】:

  • 你用的是同一个终端,客户端支持utf8吗?

标签: mysql windows mariadb freebsd


【解决方案1】:

问题 #1: 始终使用 utf8(或 utf8mb4)。 latin1 没有 Ω。你很幸运在任何一个系统上都能看到它。请参阅Trouble with utf8 characters; what I see is not what I stored中的“最佳实践”

问题 #2: 在 Windows 上,cmd 不一定默认支持 UTF-8。命令“chcp”控制“代码页”。 chcp 65001 提供 UTF-8,但它也需要安装一个特殊的字符集。在控制台窗口中设置字体:右键单击窗口标题 → 属性 → 字体 → 选择 Lucida Console 。

检查:要查看数据是否存储正确(在整个更改为 utf8mb4 之后),SELECT HEX(...) ... 以查看您是否获得了 Omega 的 CEA9。如果你得到C38EC2A9,你有“双重编码”。以 UTF-8 编码时,其他希腊字母将是 CExxCFxx

【讨论】:

  • 似乎,在 Windows 上,没有办法设置默认字符集和排序规则(至少对于 MariaDB)。请务必在您的 CREATE DATABASE 语句中设置这些属性。
  • @CharlieReitzel - 不仅要担心列的字符集和排序规则(以及表和数据库的),而且还要担心告诉 MySQL 客户端使用什么字符集.
  • 我的解决方法是:set global collation_database = utf8mb4_general_ci; set global collation_server = utf8mb4_general_ci; set global character_set_server = utf8mb4;
猜你喜欢
  • 2018-09-30
  • 2012-10-26
  • 1970-01-01
  • 2023-03-17
  • 1970-01-01
  • 2011-08-21
  • 1970-01-01
  • 1970-01-01
  • 2013-05-31
相关资源
最近更新 更多