前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >技术分享 | 如何在 OBClient 客户端实现自定义输出显示

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

作者头像
爱可生开源社区
发布2023-08-18 19:29:55
3880
发布2023-08-18 19:29:55
举报

作者:孙桥

爱可生华东交付服务部 DBA 成员,主要负责 MySQL 故障处理及相关技术支持。

本文来源:原创投稿

* 爱可生开源社区出品,原创内容未经授权不得随意使用,转载请联系小编并注明来源。


突发奇想

OBClient 是连接数据库的客户端工具。可同时兼容访问 OceanBase 数据库的 MySQL 以及 Oracle 租户。

在经常使用的过程中,突发奇想给自己的 OBClient 定制给特殊的标签显示。

修改前效果

修改后效果

以下是本人调整方法,仅供参考(●'◡'●)

1、安装依赖并拉取 OceanBase 源码

代码语言:javascript
复制
[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

代码语言:javascript
复制
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 %lu\nServer version: %s\n",
 
          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

代码语言:javascript
复制
#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 客户端包

代码语言:javascript
复制
[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 登录数据库,查看到客户端输出内容已更改为预想的样子。

代码语言:javascript
复制
[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# #源码#

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2023-05-29,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 爱可生开源社区 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 修改前效果
    • 修改后效果
    • 1、安装依赖并拉取 OceanBase 源码
    • 2、修改源代码文件
    • 3、编译源码生成 OBClient 客户端包
    • 验证完成
    相关产品与服务
    数据库
    云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档