mysql utf8四字节_MySQL在3字节中编码4字节utf8字符串值不正确

根据mysql documentation,它只支持最多3字节的utf-8unicode编码。

我的问题是,如何替换数据库中需要4字节utf-8编码的字符?我如何解码这些字符以便准确地显示用户所写的内容?在

集成测试的一部分:description = u'baaam á ✓ ✌ ❤'

print description

test_convention = Blog.objects.create(title="test title",

description=description,

login=self.user,

tag=self.tag)

错误:

^{pr2}$

表的配置:+----------------------------------+--------+---------+-------------------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+----------+----------------+---------+

| Name | Engine | Version | Collation | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Checksum | Create_options | Comment |

+----------------------------------+--------+---------+-------------------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+----------+----------------+---------+

| blogs_blog | InnoDB | 10 | utf8_general_ci | Compact | 25 | 1966 | 49152 | 0 | 32768 | 0 | 35 | 2014-02-09 00:57:59 | NULL | NULL | NULL | | |

+----------------------------------+--------+---------+-------------------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+----------+----------------+---------+

更新:我已经将表和列的配置从utf-8更改为utf8mb4,但仍然得到相同的错误,有什么想法吗?在+----------------------------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+

| Name | Engine | Version | Row_format | Rows | Avg_row_length | Data_length | Max_data_length | Index_length | Data_free | Auto_increment | Create_time | Update_time | Check_time | Collation | Checksum | Create_options | Comment |

+----------------------------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+

| blogs_blog | InnoDB | 10 | Compact | 5 | 3276 | 16384 | 0 | 32768 | 0 | 36 | 2014-02-17 22:24:18 | NULL | NULL | utf8mb4_general_ci | NULL | | |

+----------------------------------+--------+---------+------------+------+----------------+-------------+-----------------+--------------+-----------+----------------+---------------------+-------------+------------+--------------------+----------+----------------+---------+

以及:+---------------+--------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+

| Field | Type | Collation | Null | Key | Default | Extra | Privileges | Comment |

+---------------+--------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+

| id | int(11) | NULL | NO | PRI | NULL | auto_increment | select,insert,update,references | |

| title | varchar(500) | latin1_swedish_ci | NO | | NULL | | select,insert,update,references | |

| description | longtext | utf8mb4_general_ci | YES | | NULL | | select,insert,update,references | |

| creation_date | datetime | NULL | NO | | NULL | | select,insert,update,references | |

| login_id | int(11) | NULL | NO | MUL | NULL | | select,insert,update,references | |

| tag_id | int(11) | NULL | NO | MUL | NULL | | select,insert,update,references | |

+---------------+--------------+--------------------+------+-----+---------+----------------+---------------------------------+---------+

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值