mysql中的编码,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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值