Mysql – Error on updating a field with binary values

blobhexMySQLmysql-5.7varchar

I have a problem on emoji showing on webpage after migration to new DB Server. But I have a workaround. I will get the binary values of a certain field of TABLE1 on our OLD DB Server. Then update the TABLE1 on the new server using the script below:

UPDATE old_table t1 INNER JOIN new_table t2 ON t1.id = t2.id
SET t2.message = CAST(CONCAT("0x",HEX(t1.message)) AS BINARY);

But after executing this my message field on the new table becomes "0x1E395565"

If I do this script below, it will show the real message. But doing this for a million of records will take too long to execute hence the UPDATE INNER JOIN:

UPDATE new_table SET message = 0x1E395565 where id =1;

How to update this correctly? I concat "0x" on the HEX(t1.message) because when I do a mysqldump –hex-blob and charset=BINARY. There are 0x on the values.

My data type for message field is VARCHAR(1000) I know this might be wrong but is there any workaround without altering the table.

Best Answer

Simply use UNHEX("1E395565").

There could be a lot of other issues going on. So please provide SHOW CREATE TABLE for the old and new tables. Also provide a sample of what is in the old table, but use

SELECT col, HEX(col) FROM ... WHERE ...

so we can see the value in an unambiguous way. (That is, not mangled or "fixed" by the client.)

Where does 1E395565 come from? It is not anything meaningful (not utf8, etc) that I recognize.