简体   繁体   English

如何在 MySQL 表中存储 base64 信息?

[英]How to store base64 information in a MySQL table?

I've done some research, and I don't fully understand what I found.我做了一些研究,但我不完全理解我的发现。

My aim is to, using a udp listener I wrote in python, store data that it receives from an MT4000 telemetry device.我的目标是使用我在 python 中编写的 udp 侦听器,存储它从 MT4000 遥测设备接收的数据。 This data is received and read in hex, and I want that data to be put into a table, and store it as a string in base64.以十六进制接收和读取此数据,我希望将该数据放入表中,并将其作为字符串存储在 base64 中。 In terms of storing something as an integer by using the 'columnname' INT format, I would like to know how to store the information as base64?在使用 'columnname' INT 格式将某些内容存储为整数方面,我想知道如何将信息存储为 base64? ie. IE。 'data' TEXT(base64)? “数据”文本(base64)? or something similar.或类似的东西。

Could I do this by simply using the TEXT datatype, and encode the data in the python program?我可以通过简单地使用 TEXT 数据类型来做到这一点,并在 python 程序中对数据进行编码吗?

I may be approaching this in the wrong way, as I may have misinterpreted what I read online.我可能以错误的方式处理这个问题,因为我可能误解了我在网上阅读的内容。 I would be very grateful for any help.我将不胜感激任何帮助。 Thanks,谢谢,

Ed埃德

You can just save the base64 string in a TEXT column type.您可以将 base64 字符串保存在 TEXT 列类型中。 After retrieval just decode this string with base64.decodestring(data) !检索后只需使用 base64.decodestring(data) 解码此字符串!

您可以在TEXT列类型中存储 base64 字符串,但根据我的经验,我建议使用LONGTEXT类型以避免大 base64 文本中的截断错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM