作者:孙桥
爱可生华东交付服务部 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 %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 in cache
unpack package ... SUCCESS
find package in cache
unpack package ... 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 客户端自定义输出的方法,有兴趣的同学也可以试试⸜( •ᴗ• )⸝
关于 SQLE
爱可生开源社区的 SQLE 是一款面向数据库使用者和管理者,支持多场景审核,支持标准化上线流程,原生支持 MySQL 审核且数据库类型可扩展的 SQL 审核工具。
SQLE 获取
提交有效 pr,高质量 issue,将获赠面值 200-500 元(具体面额依据质量而定)京东卡以及爱可生开源社区精美周边!更多关于 SQLE 的信息和交流,请加入官方QQ交流群:637150065