关于oceanbase:技术分享-如何在-OBClient-客户端实现自定义输出显示

6次阅读

共计 4550 个字符,预计需要花费 12 分钟才能阅读完成。

突发奇想

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 %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

#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 客户端自定义输入的办法,有趣味的同学也能够试试 ⸜(•ᴗ•)⸝

正文完
 0