输出blob而不是文本

输出blob而不是文本

本文介绍了MYSQL | ENCODE()输出blob而不是文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我试图通过ENCODE()函数对一个简单的字符串进行编码。使用一个字符串,它给我的文本作为输出。但是使用一个字段给我BLOB。如何处理BLOB并输出编码字段的文本?



以下是发生的情况:



SELECT ENCODE('myText,'myPw')

- 输出:baddade4b04e // Goal = This + using fieldname



SELECT ENCODE(Field,'myPw')FROM myTable br>
- 输出:[BLOB - 14B]






我试过的:



SELECT CAST(ENCODE(Field,'myPw')AS CHAR(1000)CHARACTER SET utf8 )FROM myTable

- 输出:空行!



SELECT CONVERT(ENCODE(Field,'myPw')USING utf8)FROM myTable

- 输出:%(输出为1-2个字符,不能正确)



想象一下,我有一个列用户。现在我希望PaulPeter被编码是相同的,无论是编码字符串PaulPeter还是字段用户,其值为PaulPeter。



有人可以向我解释一下吗?非常感谢!



加密字符串





加密字段:





MySQL客户端版本:5.5.41

用户 text utf8_bin






编辑:



我在解码时遇到另一个问题:

编码完成后,我也遇到与AES_Encryption相同的问题。当我加密一个字符串时,我得到一个字符串的输出。当使用字符串值加密字段时,我得到blob。 (完全令人讨厌)

解决方案

您的用户列类型为TEXT,请尝试将该列转换为CHAR:

  SELECT AES_ENCRYPT(CAST(Field AS CHAR(1000)),'myPw')FROM myTable 


Im trying to encode a simple string by the ENCODE()-function. Using a string it gives me text as output. But using a field it gives me BLOB. How can I get around BLOB and output text for encoded fields?

Here's what happens:

SELECT ENCODE('myText,'myPw')
- Output: baddade4b04e // Goal = This + using fieldname

SELECT ENCODE(Field,'myPw') FROM myTable
- Output: [BLOB - 14B]


What I've tried:

SELECT CAST(ENCODE(Field,'myPw') AS CHAR(1000) CHARACTER SET utf8) FROM myTable
- Output: Empty rows!

SELECT CONVERT(ENCODE(Field,'myPw') USING utf8) FROM myTable
- Output: % (Output is 1-2 chars, cant be right)

Imagine I have a column user. Now I want "PaulPeter" being encoded the same regardless of whether Im encoding the string "PaulPeter" or the field user where the value is "PaulPeter".

Could anyone explain this to me? Thanks very much!

Encrypted string:

Encrypted field:

MySQL-Client-Version: 5.5.41
user: text utf8_bin


EDIT:

I got another question according decoding here: Click
After being able to encode, I got the same problem there with AES_Encryption. When I encrypt a string I get the output as a string. When encrypting a field with a string-value I get blob. :( Totally annoying.

解决方案

Your user column is of type TEXT. Try casting just that column to CHAR:

SELECT AES_ENCRYPT(CAST(Field AS CHAR(1000)),'myPw') FROM myTable

这篇关于MYSQL | ENCODE()输出blob而不是文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 09:00