我在跟踪为什么我的MariaDB的Windows开发安装与我的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.23-MariaDB FreeBSD Ports vs 10.1.19-MariaDB mariadb.org二进制发行版。
答案 0 :(得分:0)
问题#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控制台。
检查:要查看数据是否存储正确(在更改为utf8mb4之后),SELECT HEX(...) ...
以查看您是否获得了Omega的CEA9
。如果你得到C38EC2A9
,你就有了“双重编码”。当以UTF-8编码时,其他希腊字母将为CExx
或CFxx
。