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 k8s部署jupyterlab,jupyterlab保存不了文件
    • ¥15 ubuntu虚拟机打包apk错误
    • ¥199 rust编程架构设计的方案 有偿
    • ¥15 回答4f系统的像差计算
    • ¥15 java如何提取出pdf里的文字?
    • ¥100 求三轴之间相互配合画圆以及直线的算法
    • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
    • ¥15 名为“Product”的列已属于此 DataTable
    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题