Databases 8 min read

Customizing OBClient Welcome Message by Modifying Source Code

This article explains how to customize the OBClient client’s welcome output by installing dependencies, cloning the OceanBase OBClient source, editing specific source files to replace default strings, recompiling the client, installing the new package, and verifying the changed prompts.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
Customizing OBClient Welcome Message by Modifying Source Code

OBClient is a database client that can connect to OceanBase using MySQL or Oracle protocols. The author wanted to replace the default welcome messages with custom tags.

1. Install dependencies and clone the source code

[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

2. Modify source files

In obclient/client/mysql.cc locate line 1478 and replace the string "Welcome to the OceanBase..." with a custom name (e.g., "zhoujige"). Also adjust the copyright notice and default prompt strings.

if (!status.batch) {
    /// locate line 1478, replace OceanBase with custom name
    put_info("Welcome to the zhoujige.  Commands end with ; or \\g.", INFO_INFO);
    my_snprintf((char*)glob_buffer.ptr(), glob_buffer.alloced_length(),
        /// locate line 1481, replace OceanBase with custom name
        "Your zhoujige 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") : "obclient [\\d]> ", MYF(MY_WME));
current_prompt = my_strdup(default_prompt, MYF(MY_WME));

In obclient/include/welcome_copyright_notice.h replace the macro OB_WELCOME_COPYRIGHT_NOTICE to use the custom name.

#define OB_WELCOME_COPYRIGHT_NOTICE(first_year) \
  "Copyright (c) " first_year ", " COPYRIGHT_NOTICE_CURRENT_YEAR \
  ", OceanBase and/or its affiliates. All rights reserved.\n"
// change "OceanBase" to the desired name, e.g., "zhoujige"

3. Compile the modified source

[root@10-186-61-36 ~]# cd obclient/rpm/
[root@10-186-61-36 rpm]# sh obclient-build.sh
…
[BUILD] make rpms done
[root@10-186-61-36 rpm]# ll -h
‑rw‑r‑‑‑‑‑‑‑ 1 root root 12M May 26 15:44 obclient-2.2.2-1.el7.x86_64.rpm   /// compiled rpm package
[root@10-186-61-36 rpm]# rpm -ivh obclient-2.2.2-1.el7.x86_64.rpm   /// install client

4. Verify the custom output

[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.
…
zhoujige [(none)]>

The article concludes that the above steps successfully customize the OBClient welcome message, and encourages readers to try it themselves.

CompilationMySQLOceanBaseSource Code Modificationdatabase clientOBClient
Aikesheng Open Source Community
Written by

Aikesheng Open Source Community

The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.