数据库中的二进制数据,一滴VS COM pressed的base64 [英] binary data in database, blob vs compressed base64

查看:186
本文介绍了数据库中的二进制数据,一滴VS COM pressed的base64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个名为斑点在数据库中的列类型,它用于存储二进制数据。

There is a column type named blob in database, and it is used to store binary data.

但更多的往往不是,我看的解决方案,COM preSS的二进制数据,然后将其转换二进制数据为Base64和存储的base64字符串作为数据库的varchar或文本。

But more often than not, I see solutions which compress binary data, then convert binary data to base64, and store base64 string as varchar or text in database.

Python的code例如:

Python code example:

import zlib, base64
base64_str = base64.b64encode(zlib.compress(binary_data, 9))

因此​​,有二进制数据存储到数据库两种方式:

So there are two ways to store binary data into database:


  1. 为BLOB

  2. 作为COM pressed的base64

我的问题是:
哪种方式更好,为什么?

My Questions is: Which way is better and why?

推荐答案

看来,我得回答我的问题。在大多数情况下,存储COM pressed的base64到数据库中是不是一个好主意。它比存储BLOB复杂。而大多数时候,二进制比的base64字符串较小。

It seems that I have to answer my own question. Most of the time, storing compressed base64 into database is not a good idea. It is complex than storing blob. And most of the time, binary is smaller than base64 string.

我只找到一个情况下COM pressed Base64是有用的:你不能改变表模式,并且只有文本列,你必须二进制数据存储到该表。唯一可能的途径是将二进制转换为Base64字符串。

I only find one case that compressed base64 is useful: you can't alter the table schema, and there is only text columns, you have to store binary data into that table. The only possible way is to convert binary to base64 string.

这篇关于数据库中的二进制数据,一滴VS COM pressed的base64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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