序列化(数据)的哪个mysql列类型? [英] Which mysql column type for serialize(data)?

查看:38
本文介绍了序列化(数据)的哪个mysql列类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 php 中序列化了很多数组,这些数组将使用 mysql 存储在数据库中.

I am serializing alot of arrays in php that are to be stored in a database using mysql.

最终字符串的长度可以在 2000 到 100,000+ 之间变化很大,我想知道最好的列类型是什么?

The length of the final string can vary greatly from anything inbetween 2000 to 100,000+, I was wondering what would the best column type for this to be?

我目前将它设置为 LONGTEXT 但我觉得这太过分了!该数据库已经处于活动状态,大约有 300 万行,这是一个即将添加的新列.

I currently have it set as LONGTEXT but I feel this is overkill! The database is already active and has around 3million rows this is a new column which will added soon.

谢谢

推荐答案

始终使用任何 BLOB 数据类型 用于序列化数据,以便它不会被切断并以二进制安全的方式破坏序列化.如果最终字符串的长度没有最大值,那么您将需要 LONGBLOB.如果您知道数据不会填充 2^24 个字符,您可以使用 MEDIUMBLOB.MEDIUMBLOB 大约为 16MB,而 LONGBLOB 大约为 4GB,所以我会说你使用 MEDIUMBLOB 非常安全.

Always use any BLOB data-type for serializing data so that it does not get cut off and break the serialization in a binary safe manner. If there is not a maximum to the length of the final string then you will need LONGBLOB. If you know that the data won't fill 2^24 characters you could use a MEDIUMBLOB. MEDIUMBLOB is about 16MB while LONGBLOB is about 4GB so I would say you're pretty safe with MEDIUMBLOB.

为什么是二进制数据类型?MySQL 中的文本数据类型具有编码.字符编码将影响序列化数据在不同编码之间的转换方式.例如.当存储为 Latin-1 但随后以 UTF-8 读出时(例如,由于数据库驱动程序连接编码设置),序列化数据可能会被破坏,因为二进制偏移量确实发生了变化,但序列化数据并未针对此类变化进行编码.PHP 的序列化字符串是二进制数据,没有任何特定的编码.

Why a binary data type? Text data types in MySQL have an encoding. Character encoding will have an effect on how the serialized data is transposed between the different encodings. E.g. when stored as Latin-1 but then read out as UTF-8 (for example because of the database driver connection encoding setting), the serialized data can be broken because binary offsets did shift however the serialized data was not encoded for such shifts. PHP's serialized strings are binary data, not with any specific encoding.

这篇关于序列化(数据)的哪个mysql列类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆