简体   繁体   English

MySql Sequel Pro 上表情符号的 varchar 长度

[英]MySql varchar length for emojis on Sequel Pro

I'm using MySql version 5.6.46 on Linux.我在 Linux 上使用 MySql 版本 5.6.46。 I have a column name varchar(50) COLLATE utf8mb4_bin and ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 .我有一个列name varchar(50) COLLATE utf8mb4_binENGINE=InnoDB DEFAULT CHARSET=utf8mb4

When I tried to insert some data into the table.当我试图向表中插入一些数据时。 I find that,我发现,

for a (1 byte in utf8), it can store 50 maximum.对于a (utf8 中的 1 个字节),它最多可以存储 50 个。

for(3 bytes in utf8, Chinese character love), it can store 50 maximum. for(utf8 3字节,汉字love),最多可存储50个。

for为了(4 bytes in utf8, hex F09F9881 ), it can store 25 maximum. (utf8 中 4 个字节,十六进制F09F9881 ),它最多可以存储 25 个。

This confuses me.这让我很困惑。 Why Mysql is not treating one emoji as one character?为什么 Mysql 不将一个表情符号视为一个字符? If Mysql does the byte-count limit and improperly uses 3-byte-per-character, I'm expecting it can store 50*3/4=37.如果 Mysql 执行字节数限制并且不正确地使用每个字符 3 个字节,我希望它可以存储 50*3/4=37。 How on earth Mysql do the restriction? Mysql到底是怎么做限制的?

----------UPDATE------------- - - - - - 更新 - - - - - - -

Thanks to your response, I figure it out.感谢您的回复,我明白了。 I am on MacOS X and I was using Sequel Pro 1.1.2 .我在 MacOS X 上,我使用的是Sequel Pro 1.1.2 When I edit table content in the UI of the software, the maximum is 25 emoji and it toasts warning maximum text length is set to 50当我在软件的 UI 中编辑表格内容时,最大为 25 个表情符号,并且敬酒警告maximum text length is set to 50

Then I tried the raw hex approach on the server set name = X'F09F9881...F09F9881' and it can hold 50 emojis perfectly.然后我在服务器set name = X'F09F9881...F09F9881'上尝试了原始十六进制方法,它可以完美容纳 50 个表情符号。

So this is a Sequel Pro issue.所以这是一个 Sequel Pro 问题。 I will add Sequel Pro tag to this question.我将在这个问题中添加Sequel Pro标签。 Hope this will help people who met the same issue.希望这会帮助遇到同样问题的人。 Thanks谢谢

No arithmetic needed.不需要算术。

varchar(50)

Holds 50 characters of any type.可容纳 50 个任意类型的字符 This will occupy up to 202 bytes (4 * 50 + 2 for a hidden length field).这将占用最多 202个字节(隐藏长度字段为 4 * 50 + 2)。

To debug your situation, please provide:要调试您的情况,请提供:

SELECT VARIABLES LIKE 'char%';

SELECT col, HEX(col) FROM ...  -- to show what was stored.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM