OceanBase
English日本語简体中文
Docs Home
Products
Integrations
Release Notes

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog Service

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Databases

OceanBase DatabaseOceanBase Cloud OceanBase Best Practices

Connectors and Middleware

OceanBase Database Proxy OceanBase Connector/C OceanBase Connector/J OceanBase Connector/ODBC OceanBase Connector/NETOceanBase Command-Line Client

Tools

OceanBase Cloud PlatformOceanBase Migration ServiceOceanBase Developer CenterOceanBase Migration AssessmentOceanBase Admin ToolOceanBase Loader and DumperOceanBase DeployerKubernetes operator for OceanBaseOceanBase Diagnostic Tool OceanBase Binlog Service
OceanBase DatabaseOceanBase Cloud ToolsConnectors and MiddlewareLifecycle Support Policy

OceanBase Command-Line Client

V2.2.13
  • Introduction
    • Overview of OBClient
  • Quick start
    • Quick start with OBClient
  • Command-line options
    • Common OBClient command-line options
    • Reference for OBClient command-line options
    • SQL context when a script fails
  • Configuration and environment
    • Configure OBClient and set environment variables
  • User guide
    • Reference for OBClient internal commands
  • Advanced features
    • Support for Oracle-compatible mode in OBClient
    • Log in to OBClient through a socket5 proxy
    • Multi-IP connection support for OBClient
    • Client IP passthrough and tenant allowlist (F5 scenario)
    • Log in as a proxy user of OBClient
    • LOAD DATA LOCAL INFILE
    • SET variables
    • Supported login_path options for OBClient
  • Tips and troubleshooting
    • OBClient Usage Tips and Troubleshooting

Download PDF

Document Feedback
  1. Documentation Center
  2. OceanBase Command-Line Client
  3. V2.2.13

Configure OBClient and set environment variables

Last Updated:2026-09-02 09:17:42

Configuration file
Configuration file options
Option groups
Sample configuration file
Environment variables
OBClient environment variables
libobclient environment variables
History files
login.sql script
Method 1: Use the OBCLIENT_LOGIN_FILE environment variable
Method 2: Use the OBCLIENT_PATH environment variable
Example login.sql script
References

This topic describes how to use the configuration file, environment variables, and login.sql script of OBClient.

Configuration file

In addition to reading options from the command line, obclient can also read them from a configuration file. If an unknown option is provided to obclient, it is ignored.

Configuration file options

The following options are related to how the OceanBase command-line tool processes configuration files. They must be specified as the first parameter on the command line:

Options
Description
--print-defaults Prints the program parameter list and exits.
--no-defaults Do not read default options from any option file.
--defaults-file=# Read default options only from the given file #.
--defaults-extra-file=# Read this file after reading the global file.
--defaults-group-suffix=# In addition to the default option group, option groups with the following suffixes are also read. If not set, OceanBase checks$MYSQL_GROUP_SUFFIXEnvironment variables.
--login-path=# From the encrypted login file (~/.mylogin.cnf) reads the credentials for the specified login path. It must be provided as the first parameter.

Option groups

obclient reads options from the following option groups in the configuration file:

group
Description
[mysql] General MySQL compatibility option group.
[client] Options common to all client programs (recommended configuration here:host、port、user(etc.).
[client-server] Option groups shared by the client and server (such assocket、port).

Sample configuration file

You can set the following parameters in the configuration file:

[obclient]
host=127.0.0.1
port=2881
user=root@sys
password=your_password
database=testdb

Environment variables

OBClient supports the following environment variables to configure client behavior:

OBClient environment variables

Environment Variables
Description
Example
OBCLIENT_LOGIN_FILE Specifies the path of the SQL script file to be executed during login. export OBCLIENT_LOGIN_FILE=/data/login.sql
OBCLIENT_PATH Specifies the directory for login script files. OBClient searches for them in this directory.obclient_login.sqlFile. export OBCLIENT_PATH=/data
DISABLE_SET_NUM_WIDTH Controls whether the SET NUMWIDTH command takes effect. Set to0It is enabled by default and disabled by default. export DISABLE_SET_NUM_WIDTH=0
MYSQL_HISTFILE Specifies the path of the historical file. Default value:$HOME/.mysql_history. export MYSQL_HISTFILE=/dev/null
MYSQL_TCP_PORT Specify the default TCP/IP port number. export MYSQL_TCP_PORT=2881
MYSQL_UNIX_PORT Specifies the default Unix socket file path. export MYSQL_UNIX_PORT=/tmp/mysql.sock
MYSQL_PWD Specify a default password (not recommended, as it poses security risks). export MYSQL_PWD=password
PAGER Specify the pager program. export PAGER=less

libobclient environment variables

Environment Variables
Description
Example
NLS_DATE_FORMAT Set the date format. export NLS_DATE_FORMAT="YYYYMMDD"
NLS_TIMESTAMP_FORMAT Sets the TIMESTAMP format. export NLS_TIMESTAMP_FORMAT="YYYY-MM-DD HH24:MI:SS:FF3"
NLS_TIMESTAMP_TZ_FORMAT Set the format to TIMESTAMP WITH TIME ZONE. export NLS_TIMESTAMP_TZ_FORMAT="YYYY-MM-DD HH24:MI:SS"
OBCI_TNS_FILE Set the TNS file path. export OBCI_TNS_FILE=/data/obci_tnsnames.ora
TNS_ADMIN Set the TNS management directory path. export TNS_ADMIN=/data
ORACLE_HOME Set the Oracle home directory path. export ORACLE_HOME=/data
OBCLIENT_PLUGIN_DIR Set the plugin directory path. export OBCLIENT_PLUGIN_DIR=/data/
ENABLE_PROTOCOL_OB20 Controls whether to enable the OB 2.0 protocol. Set to0It is disabled by default and enabled by default. export ENABLE_PROTOCOL_OB20=0
ENABLE_PREPARE_EXECUTE Controls whether to enable the PS protocol. Set to0The PS protocol is enabled by default, and the combined protocol is used by default. export ENABLE_PREPARE_EXECUTE=0

History files

On Unix, the OBClient writes executed statements to a history file. By default, this file is named .mysql_history and is created in your home directory.

Notice

The .mysql_history file may contain sensitive information (such as SQL statements with passwords). It is recommended to protect this file using restricted access mode. If you do not want to maintain a history file, you can set the MYSQL_HISTFILE environment variable to /dev/null.

login.sql script

OBClient supports automatically executing SQL scripts during login. You can configure this in the following two ways:

Method 1: Use the OBCLIENT_LOGIN_FILE environment variable

Set the environment variable to specify the login script file:

export OBCLIENT_LOGIN_FILE=/data/login.sql

Method 2: Use the OBCLIENT_PATH environment variable

Set the environment variable to specify the directory for login scripts. OBClient will look for the obclient_login.sql file in this directory:

export OBCLIENT_PATH=/data

OBClient looks for the login script at the /data/obclient_login.sql path.

Example login.sql script

In the login script, you can set common SQL variables or execute initialization commands:

-- Set SQL*Plus compatibility variables
SET FEEDBACK ON;
SET HEADING ON;
SET LINESIZE 1000;

-- Set the date format.
ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS';

-- Display welcome message
SELECT 'Welcome to OceanBase!' AS message FROM dual;

References

  • Overview of OBClient
  • Reference for OBClient command-line options
  • Script error context
  • Supported login_path
  • Advanced features of OBClient

Previous topic

SQL context when a script fails
Last

Next topic

Reference for OBClient internal commands
Next
on this page
Configuration file
Configuration file options
Option groups
Sample configuration file
Environment variables
OBClient environment variables
libobclient environment variables
History files
login.sql script
Method 1: Use the OBCLIENT_LOGIN_FILE environment variable
Method 2: Use the OBCLIENT_PATH environment variable
Example login.sql script
References