存储一个base64连接codeD值MySQL数据库的最佳方式? [英] Best way to store a base64 encoded value in MySQL DB?

查看:304
本文介绍了存储一个base64连接codeD值MySQL数据库的最佳方式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有,我想在我的数据库存储的值,并归类任何区别怎么样这样的字符串

<$p$p><$c$c>YToyOntzOjIwOiJUeXBlX29mX29yZ2FuaXNhdGlvbiI7czoyMDoiTWVtYmVyIG9mIFBhcmxpYW1lbnQiO3M6ODoiUG9zdGNvZGUiO3M6NzoiUEUxIDFKQSI7fQ==

可能存储?另外,我似乎能够写出这些值到数据库的唯一方法是使用 BLOB 这似乎是将其存储的真正而走错了路。


解决方案

校勘唯一有差别,如果你需要 ORDER BY 或搜索栏。这些连接的base64 codeD项目可能不会被搜索或排序。

如果您的EN codeD项目保证在长度小于64K字节,这样定义的列:

 `columnname`文本字符集ASCII,

这正是需要些什么了一个base64 EN codeD变量;编码过程中一切都变成可显示的ASCII。

如果该项目将在长度小于16兆,但有些会比64K长,使用 MEDIUMTEXT 而不是文本

I have a value I'd like to store in my DB, does the Collation make any difference how a string like this

YToyOntzOjIwOiJUeXBlX29mX29yZ2FuaXNhdGlvbiI7czoyMDoiTWVtYmVyIG9mIFBhcmxpYW1lbnQiO3M6ODoiUG9zdGNvZGUiO3M6NzoiUEUxIDFKQSI7fQ==

Might be stored? Also, the only way I seem to be able to write these values to the DB is by using a BLOB this seems to be a really rather wrong way of storing it.

解决方案

The collation only makes a difference if you need to ORDER BY or search the column. These base64 encoded items are probably not going to be searched or sorted.

If your encoded items are guaranteed to be less than 64K bytes in length, define your column like this:

   `columnname` TEXT CHARACTER SET ascii,

This is exactly what's needed for a base64 encoded variable; the encoding process turns everything into displayable ASCII.

If the items will be less than 16 megabytes in length, but some will be longer than 64k, use MEDIUMTEXT instead of TEXT.

这篇关于存储一个base64连接codeD值MySQL数据库的最佳方式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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