技术分享 | 如何在 OBClient 客户端实现自定义输出显示

2023年 10月 12日 39.8k 0

作者:孙桥

爱可生华东交付服务部 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
[root@10-186-61-36 ~]# git clone https://github.com/oceanbase/obclient.git
Cloning into 'obclient'...
remote: Enumerating objects: 9229, done.
remote: Counting objects: 100% (299/299), done.
remote: Compressing objects: 100% (243/243), done.
remote: Total 9229 (delta 85), reused 121 (delta 44), pack-reused 8930
Receiving objects: 100% (9229/9229), 112.91 MiB | 4.14 MiB/s, done.
Resolving deltas: 100% (2960/2960), done.
Checking out files: 100% (8729/8729), done.

2、修改源代码文件

第一个文件:obclient/client/mysql.cc

if (!status.batch)
 
{
 ///定位到 1478 行,将 Oceanbase 修改为自己想要的名称,如:zhoujige
  put_info("Welcome to the OceanBase.  Commands end with ; or \g.",          
 
           INFO_INFO);
 
  my_snprintf((char*) glob_buffer.ptr(), glob_buffer.alloced_length(),
  ///定位到 1481 行,将 Oceanbase 修改为自己想要的名称,如:zhoujige
          "Your OceanBase connection id is %lunServer version: %sn",
 
          mysql_thread_id(&mysql), is_proxymode ? "":server_version_string(&mysql));
 
  put_info((char*) glob_buffer.ptr(),INFO_INFO);
 
  put_info(OB_WELCOME_COPYRIGHT_NOTICE("2000"), INFO_INFO);
 
}
 
      ......
      ......
default_prompt = my_strdup(getenv("MYSQL_PS1") ?
 
               getenv("MYSQL_PS1") :
  ///定位到 1366 行,将 obclient 修改为自己想要的名称,如:zhoujige
               "obclient [\d]> ",MYF(MY_WME));                
 
current_prompt = my_strdup(default_prompt,MYF(MY_WME));

第二个文件:obclient/include/welcome_copyright_notice.h

#define ORACLE_WELCOME_COPYRIGHT_NOTICE(first_year) 
 
  "Copyright (c) " first_year ", " COPYRIGHT_NOTICE_CURRENT_YEAR 
 
   ", Oracle, MariaDB Corporation Ab and others.n"
 
 
 
 
#define OB_WELCOME_COPYRIGHT_NOTICE(first_year) 
 
  "Copyright (c) " first_year ", " COPYRIGHT_NOTICE_CURRENT_YEAR 
 ///定位到 32 行,将 Oceanbase 修改为自己想要的名称,如:zhoujige
   ", OceanBase and/or its affiliates. All rights reserved.n"             

3、编译源码生成 OBClient 客户端包

[root@10-186-61-36 ~]# cd obclient/rpm/
[root@10-186-61-36 rpm]# sh obclient-build.sh
[BUILD] args: TOP_DIR=/root/obclient/rpm/../ PACKAGE=obclient VERSION=2.2.2 RELEASE=1
check dependencies profile for el7.x86_64... FOUND
check repository address in profile... https://mirrors.aliyun.com/oceanbase/development-kit/el/7/x86_64/
download dependencies...
find package <devdeps-openssl-static-1.0.1e-3.el7.x86_64.rpm> in cache
unpack package <devdeps-openssl-static-1.0.1e-3.el7.x86_64.rpm>... SUCCESS
find package <devdeps-ncurses-static-6.2-3.el7.x86_64.rpm> in cache
unpack package <devdeps-ncurses-static-6.2-3.el7.x86_64.rpm>... SUCCESS
[BUILD] create tmp dirs...TMP_DIR=/root/obclient/rpm/..//obclient-tmp.25255
[BUILD] make rpms...dep_dir=/root/obclient/rpm/..//deps/3rd/ spec_file=obclient.spec
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.SLcgcg
+ umask 022
+ cd /root/obclient/rpm/..//obclient-tmp.25255/BUILD
+ cd /root/obclient/rpm/../
+ exit 0
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.m2gH4b
+ umask 022
+ cd /root/obclient/rpm/..//obclient-tmp.25255/BUILD
+ cd /root/obclient/rpm/../
+ ./build.sh --prefix /u01/obclient --version 2.2.2
-- Running cmake version 2.8.12.2
-- The C compiler identification is GNU 4.8.5
-- The CXX compiler identification is GNU 4.8.5
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Looking for SHM_HUGETLB
-- Looking for SHM_HUGETLB - found
......
+ cd /root/obclient/rpm/..//obclient-tmp.25255/BUILD
+ rm -rf /root/obclient/obclient-tmp.25255/BUILDROOT/obclient-2.2.2-1.el7.x86_64
+ exit 0
[BUILD] make rpms done.
[root@10-186-61-36 rpm]# ll -h
total 12M
-rw-r--r-- 1 root root  12M May 26 15:44 obclient-2.2.2-1.el7.x86_64.rpm     /// 编译生成的rpm包
-rw-r--r-- 1 root root 1.2K May 22 14:39 obclient-build.sh
-rw-r--r-- 1 root root 1.1K May 22 14:39 obclient.deps
-rw-r--r-- 1 root root 1.8K May 22 14:39 obclient.spec
-rw-r--r-- 1 root root    6 May 22 14:39 obclient-VER.txt
[root@10-186-61-36 rpm]# rpm -ivh obclient-2.2.2-1.el7.x86_64.rpm            /// 安装obclient客户
Preparing...                          ################################# [100%]
Updating / installing...
   1:obclient-2.2.2-1.el7             ################################# [100%]

验证完成

用新生成的 OBClient 登录数据库,查看到客户端输出内容已更改为预想的样子。

[root@10-186-61-36 rpm]# obclient -h 10.186.61.36 -uroot@sys -P2881
Welcome to the zhoujige.  Commands end with ; or g.
Your zhoujige connection id is 3221559186
Server version: OceanBase 3.1.4 (r10000092022071511-b4bfa011ceaef428782dcb65ae89190c40b78c2f) (Built Jul 15 2022 11:45:14)
 
Copyright (c) 2000, 2018,  zhoujige and/or its affiliates. All rights reserved.
 
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
 
zhoujige [(none)]>
zhoujige [(none)]>

以上便是调整 OBClient 客户端自定义输出的方法,有兴趣的同学也可以试试⸜( •ᴗ• )⸝

本文关键字
:#OceanBase# #OBClient# #源码#

文章推荐:

技术分享 | 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源创计划”,欢迎正在阅读的你也加入,一起分享。

相关文章

Oracle如何使用授予和撤销权限的语法和示例
Awesome Project: 探索 MatrixOrigin 云原生分布式数据库
下载丨66页PDF,云和恩墨技术通讯(2024年7月刊)
社区版oceanbase安装
Oracle 导出CSV工具-sqluldr2
ETL数据集成丨快速将MySQL数据迁移至Doris数据库

发布评论