MySQL 8.0.19客户端的一个小变化

本文作者:叶金荣,知数堂联合创始人,MySQL DBA课程讲师。Oracle MySQL ACE,MySQL布道师。有多年MySQL及系统架构设计经验,擅长MySQL企业级应用、数据库设计、优化、故障处理等。

不注意到这个变化的话,还挺折腾人的。

在MySQL 8.0.19 Release Notes里,有这么一段话:

When the mysql client operates in interactive mode, the --binary-as-hex option now is enabled by default. In addition, output from the status (or \s) command includes this line when the option is enabled implicitly or explicitly。To disable hexadecimal notation, use --skip-binary-as-hex (Bug #24432545)

意思是如果用mysql客户端进入交互模式,那么默认启用参数 –binary-as-hex,执行 status\s时能看到下面这样的标记:

[root@yejr.me]> \s
...
Binary data as: Hexadecimal
...
Threads: 1  Questions: 88...

可以在启动客户端时加上**–skip-binary-as-hex**关闭这个参数。

那么加上参数**–binary-as-hex**后,对交互式客户端会有什么影响呢?

先看下文档里的解释:

When this option is given, mysql displays binary data using hexadecimal notation (0xvalue).

也就是说,当查询到的数据有二进制数据的话,就会用十六进制方式展示出来。

看看下面的例子吧:(建议在PC端或横版观看)

# 在 --skip-binary-as-hex 模式下
# 用CHAR()函数能把二进制转成ASCII字符
[root@yejr.me]> SELECT CHAR(77,121,83,81,'76');
+-------------------------+
| CHAR(77,121,83,81,'76') |
+-------------------------+
| MySQL                   |
+-------------------------+

# 在 --binary-as-hex(8.0.19后默认) 模式下
# 直接把二进制数据以十六进制输出了
...
Server characterset:    utf8mb4
...
UNIX socket:        /mysql/data01/mysql.sock
Binary data as:     Hexadecimal

[root@yejr.me]> SELECT CHAR(77,121,83,81,'76');
+--------------------------------------------------+
| CHAR(77,121,83,81,'76')                          |
+--------------------------------------------------+
| 0x4D7953514C                                     |
+--------------------------------------------------+

看起来是不是觉得怪怪的,很不适应。

新参数**–binary-as-hex是MySQL 5.6.37版本开始引入的,由一位叫做Daniël van Eeden的哥们建议加入的。个人不是太理解这位仁兄的脑回路,可能觉得对于二进制数据,MySQL本来就不该给智能化地转成ASCII**,而应该以码农们习惯的十六进制展示,所以能让屏幕输出看起来更酷一些?哈哈哈…

延伸阅读
  • Print binary data as hex in the mysql client #118, https://github.com/mysql/mysql-server/pull/118

  • Print binary data as hex in the mysql client (contribution), https://bugs.mysql.com/bug.php?id=84391

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值