douchun2158 2019-09-20 02:39
浏览 710

将字节数组保存到mysql时,应该将数组直接保存到Blob类型列中,还是将其编码为字符串并将其保存为VARCHAR?

As part of my app flow, I'm generating an array of 32 bytes exactly and I need to store it in MySQL for later use. I understand I can save it directly to a column of type BLOB, which is intended for saving binary large objects and they are treated as binary strings (byte string) but I'm concerned about overall performance, being that I'm actually saving just 32 bytes. I know that there's also a TINYBLOB type, but still, don't know if using it for a 32-byte string would be too much somehow.

My other alternative is to first encode my array of bytes to a string and then saving that string as VARCHAR. But I feel adding the encoding/decoding part could lead to errors like the encoder failing to encode one-byte string for some reason. Or even developer errors like someone forgetting to decode the string before using it or using the wrong type of encoder.

Observations

I'm using Go 1.12 and MySQL 5.7.23 if that makes any difference.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
    • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
    • ¥50 有数据,怎么用matlab求全要素生产率
    • ¥15 TI的insta-spin例程
    • ¥15 完成下列问题完成下列问题
    • ¥15 C#算法问题, 不知道怎么处理这个数据的转换