简体   繁体   English

如何在MySQL中将BLOB转换为文本?

[英]How can I convert BLOB to text in MySQL?

I have a BLOB field in one of tables and I used the following command to convert it to text: 我在一张表中有一个BLOB字段,并使用以下命令将其转换为文本:

ALTER TABLE mytable
ADD COLUMN field1_new TEXT;

update mytable set
field1_new = CONVERT(field1 USING utf8);

This did not work and gave me some random characters. 这没有用,给了我一些随机字符。 Like: 喜欢:

9x

This result is returned as a content of message which does not make sense. 该结果作为没有意义的消息内容返回。 I changed the character set to 'latin1'. 我将字符集更改为“ latin1”。 This one gave me a larger sequence of characters yet still something non-sense. 这给了我更多的字符序列,但仍然有些废话。 For example: 例如:

¢xœ}T]k1|/ô?¬Á/‡ZJpMK“–<$„Ô¥ôqO§»ÑI®¤³¹ß...

Is there anyway to figure out what character set the BLOB field is using so that I can convert it to text properly? 无论如何,有没有找出BLOB字段使用什么字符集,以便我可以正确地将其转换为文本?

Any help with this problem will be much appreciated. 任何有关此问题的帮助将不胜感激。 Thanks 谢谢

Edited: I have to also mention that I used CAST command and it returned: 编辑:我还必须提到我使用了CAST命令,它返回了:

�x�}T]k1|/�?��/��ZJpMK��<$�ԥ�qO���I������������$:���̬�4�...

try using cast : 尝试使用cast

CAST(field1 AS CHAR(10000) CHARACTER SET utf8)

you can see this post also for more: How do I convert from BLOB to TEXT in MySQL? 您还可以查看更多信息: 如何在MySQL中将BLOB转换为TEXT?

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

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