技术分享 | 如何在 OBClient 客户端实现自定义输出显示
作者:孙桥
爱可生华东交付服务部 DBA 成员,主要负责 MySQL 故障处理及相关技术支持。
本文来源:原创投稿
* 爱可生开源社区出品,原创内容未经授权不得随意使用,转载请联系小编并注明来源。
突发奇想
OBClient 是连接数据库的客户端工具。可同时兼容访问 OceanBase 数据库的 MySQL 以及 Oracle 租户。
在经常使用的过程中,突发奇想给自己的 OBClient 定制给特殊的标签显示。
修改前效果

修改后效果

以下是本人调整方法,仅供参考(●'◡'●)
1、安装依赖并拉取 OceanBase 源码
[root@10-186-61-36 ~]# yum install -y git cmake gcc make openssl-devel ncurses-devel rpm-build gcc-c++ bison bison-devel zlib-devel gnutls-devel libxml2-devel openssl-devel libevent-devel libaio-devel<br>[root@10-186-61-36 ~]# git clone https://github.com/oceanbase/obclient.git<br>Cloning into 'obclient'...<br>remote: Enumerating objects: 9229, done.<br>remote: Counting objects: 100% (299/299), done.<br>remote: Compressing objects: 100% (243/243), done.<br>remote: Total 9229 (delta 85), reused 121 (delta 44), pack-reused 8930<br>Receiving objects: 100% (9229/9229), 112.91 MiB | 4.14 MiB/s, done.<br>Resolving deltas: 100% (2960/2960), done.<br>Checking out files: 100% (8729/8729), done.<br>
2、修改源代码文件
第一个文件:obclient/client/mysql.cc
if (!status.batch)<br> <br>{<br> ///定位到 1478 行,将 Oceanbase 修改为自己想要的名称,如:zhoujige<br> put_info("Welcome to the OceanBase. Commands end with ; or \g.", <br> <br> INFO_INFO);<br> <br> my_snprintf((char*) glob_buffer.ptr(), glob_buffer.alloced_length(),<br> ///定位到 1481 行,将 Oceanbase 修改为自己想要的名称,如:zhoujige<br> "Your OceanBase connection id is %lunServer version: %sn",<br> <br> mysql_thread_id(&mysql), is_proxymode ? "":server_version_string(&mysql));<br> <br> put_info((char*) glob_buffer.ptr(),INFO_INFO);<br> <br> put_info(OB_WELCOME_COPYRIGHT_NOTICE("2000"), INFO_INFO);<br> <br>}<br> <br> ......<br> ......<br>default_prompt = my_strdup(getenv("MYSQL_PS1") ?<br> <br> getenv("MYSQL_PS1") :<br> ///定位到 1366 行,将 obclient 修改为自己想要的名称,如:zhoujige<br> "obclient [\d]> ",MYF(MY_WME)); <br> <br>current_prompt = my_strdup(default_prompt,MYF(MY_WME));<br>
第二个文件:obclient/include/welcome_copyright_notice.h
#define ORACLE_WELCOME_COPYRIGHT_NOTICE(first_year) <br> <br> "Copyright (c) " first_year ", " COPYRIGHT_NOTICE_CURRENT_YEAR <br> <br> ", Oracle, MariaDB Corporation Ab and others.n"<br> <br> <br> <br> <br>#define OB_WELCOME_COPYRIGHT_NOTICE(first_year) <br> <br> "Copyright (c) " first_year ", " COPYRIGHT_NOTICE_CURRENT_YEAR <br> ///定位到 32 行,将 Oceanbase 修改为自己想要的名称,如:zhoujige<br> ", OceanBase and/or its affiliates. All rights reserved.n" <br>
3、编译源码生成 OBClient 客户端包
[root@10-186-61-36 ~]# cd obclient/rpm/<br>[root@10-186-61-36 rpm]# sh obclient-build.sh<br>[BUILD] args: TOP_DIR=/root/obclient/rpm/../ PACKAGE=obclient VERSION=2.2.2 RELEASE=1<br>check dependencies profile for el7.x86_64... FOUND<br>check repository address in profile... https://mirrors.aliyun.com/oceanbase/development-kit/el/7/x86_64/<br>download dependencies...<br>find package <devdeps-openssl-static-1.0.1e-3.el7.x86_64.rpm> in cache<br>unpack package <devdeps-openssl-static-1.0.1e-3.el7.x86_64.rpm>... SUCCESS<br>find package <devdeps-ncurses-static-6.2-3.el7.x86_64.rpm> in cache<br>unpack package <devdeps-ncurses-static-6.2-3.el7.x86_64.rpm>... SUCCESS<br>[BUILD] create tmp dirs...TMP_DIR=/root/obclient/rpm/..//obclient-tmp.25255<br>[BUILD] make rpms...dep_dir=/root/obclient/rpm/..//deps/3rd/ spec_file=obclient.spec<br>Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.SLcgcg<br>+ umask 022<br>+ cd /root/obclient/rpm/..//obclient-tmp.25255/BUILD<br>+ cd /root/obclient/rpm/../<br>+ exit 0<br>Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.m2gH4b<br>+ umask 022<br>+ cd /root/obclient/rpm/..//obclient-tmp.25255/BUILD<br>+ cd /root/obclient/rpm/../<br>+ ./build.sh --prefix /u01/obclient --version 2.2.2<br>-- Running cmake version 2.8.12.2<br>-- The C compiler identification is GNU 4.8.5<br>-- The CXX compiler identification is GNU 4.8.5<br>-- Check for working C compiler: /usr/bin/cc<br>-- Check for working C compiler: /usr/bin/cc -- works<br>-- Detecting C compiler ABI info<br>-- Detecting C compiler ABI info - done<br>-- Check for working CXX compiler: /usr/bin/c++<br>-- Check for working CXX compiler: /usr/bin/c++ -- works<br>-- Detecting CXX compiler ABI info<br>-- Detecting CXX compiler ABI info - done<br>-- Looking for SHM_HUGETLB<br>-- Looking for SHM_HUGETLB - found<br>......<br>+ cd /root/obclient/rpm/..//obclient-tmp.25255/BUILD<br>+ rm -rf /root/obclient/obclient-tmp.25255/BUILDROOT/obclient-2.2.2-1.el7.x86_64<br>+ exit 0<br>[BUILD] make rpms done.<br>[root@10-186-61-36 rpm]# ll -h<br>total 12M<br>-rw-r--r-- 1 root root 12M May 26 15:44 obclient-2.2.2-1.el7.x86_64.rpm /// 编译生成的rpm包<br>-rw-r--r-- 1 root root 1.2K May 22 14:39 obclient-build.sh<br>-rw-r--r-- 1 root root 1.1K May 22 14:39 obclient.deps<br>-rw-r--r-- 1 root root 1.8K May 22 14:39 obclient.spec<br>-rw-r--r-- 1 root root 6 May 22 14:39 obclient-VER.txt<br>[root@10-186-61-36 rpm]# rpm -ivh obclient-2.2.2-1.el7.x86_64.rpm /// 安装obclient客户<br>Preparing... ################################# [100%]<br>Updating / installing...<br> 1:obclient-2.2.2-1.el7 ################################# [100%]<br>
验证完成
用新生成的 OBClient 登录数据库,查看到客户端输出内容已更改为预想的样子。
[root@10-186-61-36 rpm]# obclient -h 10.186.61.36 -uroot@sys -P2881<br>Welcome to the zhoujige. Commands end with ; or g.<br>Your zhoujige connection id is 3221559186<br>Server version: OceanBase 3.1.4 (r10000092022071511-b4bfa011ceaef428782dcb65ae89190c40b78c2f) (Built Jul 15 2022 11:45:14)<br> <br>Copyright (c) 2000, 2018, zhoujige and/or its affiliates. All rights reserved.<br> <br>Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.<br> <br>zhoujige [(none)]><br>zhoujige [(none)]><br>
以上便是调整 OBClient 客户端自定义输出的方法,有兴趣的同学也可以试试⸜( •ᴗ• )⸝
本文关键字
:#OceanBase# #OBClient# #源码#
<h5 data-tool="mdnice编辑器"></h5>
文章推荐:
技术分享 | OceanBase 慢查询排查思路
技术分享 | OceanBase写入限速源码解读
故障分析 | innodb_thread_concurrency 导致数据库异常的问题分析
故障分析 | OceanBase 频繁更新数据后读性能下降的排查
故障分析 | MySQL 升级到 8.0 变慢问题分析
技术分享 | 一招解决 MySQL 中 DDL 被阻塞的问题
故障分析 | 一条本该记录到慢日志的 SQL 是如何被漏掉的
关于 SQLE
爱可生开源社区的 SQLE 是一款面向数据库使用者和管理者,支持多场景审核,支持标准化上线流程,原生支持 MySQL 审核且数据库类型可扩展的 SQL 审核工具。
SQLE 获取
类型 | 地址 |
---|---|
版本库 | https://github.com/actiontech/sqle |
文档 | https://actiontech.github.io/sqle-docs-cn/ |
发布信息 | https://github.com/actiontech/sqle/releases |
数据审核插件开发文档 | https://actiontech.github.io/sqle-docs-cn/3.modules/3.7_auditplugin/auditplugin_development.html |
提交有效 pr,高质量 issue,将获赠面值 200-500 元(具体面额依据质量而定)京东卡以及爱可生开源社区精美周边!
更多关于 SQLE 的信息和交流,请加入官方QQ交流群:637150065
本文分享自微信公众号 - 爱可生开源社区(ActiontechOSS)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。