我有以下数据:Trollhättan

  • 如果我打印并设置标题 utf-8, ,这是浏览器中的输出。

  • 如果我不设置 utf-8 在标题中, Trollhättan. 。但是,当我将数据存储在数据库中并进行检查时 phpmyadmin, ,我收到以下字符串:trollhãƒâttan。

  • 当我设置标头时 utf-8, ,我得到了这个字符串: Trollhättan 除此之外 Trollhättan.

由于表是 latin1_swedish_ci, ,我必须在桌子中使用吗 UTF-8?

有帮助吗?

解决方案

这是UTF-8下的校正列表

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)

latin1_swedish_ci 属于Latin1

mysql> select * from information_schema.collations where COLLATION_NAME = 'latin1_swedish_ci';
+-------------------+--------------------+----+------------+-------------+---------+
| COLLATION_NAME    | CHARACTER_SET_NAME | ID | IS_DEFAULT | IS_COMPILED | SORTLEN |
+-------------------+--------------------+----+------------+-------------+---------+
| latin1_swedish_ci | latin1             |  8 | Yes        | Yes         |       1 |
+-------------------+--------------------+----+------------+-------------+---------+
1 row in set (0.03 sec)

您的整理最接近的UTF8是ID 200

mysql> select * from information_schema.collations where ID = 200;
+-----------------+--------------------+-----+------------+-------------+---------+
| COLLATION_NAME  | CHARACTER_SET_NAME | ID  | IS_DEFAULT | IS_COMPILED | SORTLEN |
+-----------------+--------------------+-----+------------+-------------+---------+
| utf8_swedish_ci | utf8               | 200 |            | Yes         |       8 |
+-----------------+--------------------+-----+------------+-------------+---------+
1 row in set (0.00 sec)

警告

您可能必须尝试Latin1,更改表格中单个列的字符集和整理,或者两者都可能。至少,使用latin1在phpmyadmin中显示。

您可以进行Tweek并尝试使整个数据库成为特定的字符集,并使用 Alter数据库.

ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;

确保您对数据库进行备份,然后将其加载到DEV/分期DB中,然后通过Dev/Staging运行Alter数据库。

其他提示

您需要确保当您“将数据存储在数据库中”时, 客户 您使用的是使用UTF8。然后将HTTP标头设置为UTF8完成往返。

令人惊讶的是,数据库中使用了哪些字符集并不重要(尽管也很方便它也可以成为UTF8)。

许可以下: CC-BY-SA归因
不隶属于 dba.stackexchange
scroll top