mysql – 表中的字符集编码
作者:互联网
我有以下数据: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中显示.
您可以调整并尝试使用ALTER DATABASE将整个数据库设置为特定字符集和排序规则.
ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci;
确保备份数据库并将其加载到dev / staging DB中,然后针对dev / staging运行ALTER DATABASE.
标签:mysql,character-set 来源: https://codeday.me/bug/20190806/1603797.html