在命令行中的Unicode转义序列MySQL [英] Unicode escape sequence in command line MySQL

查看:520
本文介绍了在命令行中的Unicode转义序列MySQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简短版本:

在命令行mysql中可以使用什么样的转义序列搜索unicode字符?

What kind of escape sequence can one use to search for unicode characters in command line mysql?

长版本

我正在寻找一种方法,一个unicode序列,U + 200B,在mysql从命令行。我不知道使用哪种逃跑。我尝试过\\\​和 x200B ,甚至​我终于找到一个博客,建议_utf8语法。这将在命令行上生成字符:

I'm looking for a way to search a column for records containing a unicode sequence, U+200B, in mysql from the command line. I can't figure out which kind of escape to use. I've tried \u200B and x200B and even ​ I finally found one blog that suggested the _utf8 syntax. This will produce the character on the command line:

select _utf8 x'200B';

现在我被困在一个LIKE查询中。

Now I'm stuck trying to get that working in a "LIKE" query.

这会生成字符,但是放在LIKE部分时,%似乎失去了它们的特殊意义:

This generates the characters, but the % seem to lose their special meaning when placed in the LIKE part:

select _utf8 x'0025200B0025';

我也试过了一个concat,但它没有工作:

I also tried a concat but it didn't work either:

select concat('%', _utf8 x'200B', '%');

更多背景

我有一些数据具有零宽度空格字符(zwsp),Unicode点U + 200B。这通常是由在其输出中使用zwsp的网站的复制/粘贴引起的。对于大多数unicode字符,我可以将字符粘贴到终端(或用键码创建它),但由于这一个是不可见的,这有点更具挑战性。我可以创建一个文件生成一个%%序列,并将其复制/粘贴到终端,它会工作,但它留下我的命令历史和终端输出screwy。

I have some data that has zero width space characters (zwsp) in it, Unicode Point U+200B. This is typically caused by copy/paste from websites that use the zwsp in their output. With most unicode characters, I can just paste the character into the terminal (or create it with a keycode), but since this one is invisible it's a bit more challenging. I can create a file that generates a "%%" sequence and copy/paste it to the terminal and it will work but it leaves my command history and terminal output screwy. I would think there is a straightforward way to do this in MySQL, but so far I've come up short.

提前感谢,

-Paul Burney

-Paul Burney

推荐答案

select _utf8 x'0025200B0025';

这不是UTF-8,它是UTF-16 / UCS-2。如果您的MySQL副本中有UCS-2支持,您可能可以说 SELECT _ucs2 0x0025200B0025

That's not UTF-8, it's UTF-16/UCS-2. You might be able to say SELECT _ucs2 0x0025200B0025 if you have UCS-2 support in your copy of MySQL.

否则,UTF-8中的字节序列编码字符U + 200B将为0xE2,0x80,0x8B:

Otherwise, the byte sequence encoding character U+200B in UTF-8 would be 0xE2, 0x80, 0x8B:

select 0xE2808B;

这篇关于在命令行中的Unicode转义序列MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆