MySQL 输出十六进制字符串为 UTF-8

Bry*_*eld 3 mysql string hex utf-8 character-encoding

这适用于 UTF8

create temporary table test (x char(1) not null) charset=utf8;
insert into test select x'c3a9';
select hex(x), x from test;
drop table test;
Run Code Online (Sandbox Code Playgroud)

产出

+--------+---+
| hex(x) | x |
+--------+---+
| C3A9   | é | 
+--------+---+
Run Code Online (Sandbox Code Playgroud)

但这使用了不是 utf8 的默认字符集

SELECT x'c3a9';
Run Code Online (Sandbox Code Playgroud)

如何更改上述单行以输出 UTF-8é而不是é

Ste*_*rig 5

SELECT CONVERT(x'c3a9' USING utf8)
Run Code Online (Sandbox Code Playgroud)

应该管用。见11.10。转换函数和运算符