---
title: ECOB 安装与配置-OceanBase数据库使用指南
description: 了解OceanBase数据库在实际应用中关于 ECOB 安装与配置相关的常见问题和使用技巧，帮助您快速解决 ECOB 安装与配置的难题。
---
切换语言

- 简体中文
- English

划线反馈

# ECOB 安装与配置

更新时间：2026-05-07 08:31

适用版本： V3.2.x、V4.2.x 内容类型：TechNote  

本文介绍 ECOB 安装与配置。ECOB 详细介绍参考官网文档[嵌入式 SQL 预编译器](https://www.oceanbase.com/docs/enterprise-ecob-cn-10000000002206700)。

## 详细说明

### 安装包准备

以 x86 机器为例，arm 机器换成对应的安装包即可。 OceanBase 相关安装包（可以联系 OceanBase 数据库技术支持获取最新版本）如下。 **注：** 需要使用 **ECOB Release Note** 中列出的 `ecob`、`obci`、`libobclient` 具体版本（可以咨询 OceanBase 数据库技术支持）以避免不必要的问题。

```shell
libobclient-2.2.6-42024052211.el7.x86_64.rpm
obci-2.0.10-22024072517.el7.x86_64.rpm
ecob-1.1.9-42024073014.el7.x86_64.rpm

```

OCI 安装包 `oracle-instantclient12.2-devel-12.2.0.1.0-1.x86_64.rpm` 请在 Oracle 官网下载（也可以联系 OceanBase 数据库技术支持获取），具体下载参见：[Oracle Instant Client Downloads for Linux x86-64 (64-bit)](https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html)。

所有安装包准备好后如下：

```shell
#ls -lh
total 5.2M
-rw-r--r-- 1 root root 258K Aug 14 17:11 ecob-1.1.9-42024073014.el7.x86_64.rpm
-rw------- 1 root root 1.6M Aug 14 17:17 libobclient-2.2.6-42024052211.el7.x86_64.rpm
-rw-r--r-- 1 root root 2.9M Aug 14 17:24 obci-2.0.10-22024072517.el7.x86_64.rpm
-rw-r--r-- 1 root root 593K Aug 14 17:10 oracle-instantclient12.2-devel-12.2.0.1.0-1.x86_64.rpm

```

### 安装 libobclient

通过如下命令安装。

```shell
#rpm -ivh libobclient-2.2.6-42024052211.el7.x86_64.rpm
warning: libobclient-2.2.6-42024052211.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID b288a9d3: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:libobclient-2.2.6-42024052211.el7################################# [100%]

```

查看安装后的所有文件。

```shell
#rpm -qa|grep libobclient
libobclient-2.2.6-42024052211.el7.x86_64

```

```shell
#rpm -ql libobclient-2.2.6-42024052211.el7.x86_64
/u01/obclient
/u01/obclient/bin
/u01/obclient/bin/mariadb_config
/u01/obclient/include
/u01/obclient/include/errmsg.h
/u01/obclient/include/ma_config.h
/u01/obclient/include/ma_global.h
/u01/obclient/include/ma_hash.h
/u01/obclient/include/ma_list.h
/u01/obclient/include/ma_pvio.h
/u01/obclient/include/ma_string.h
/u01/obclient/include/ma_sys.h
/u01/obclient/include/ma_tls.h
/u01/obclient/include/mariadb
/u01/obclient/include/mariadb/ma_io.h
/u01/obclient/include/mariadb_com.h
/u01/obclient/include/mariadb_ctype.h
/u01/obclient/include/mariadb_dyncol.h
/u01/obclient/include/mariadb_rpl.h
/u01/obclient/include/mariadb_stmt.h
/u01/obclient/include/mariadb_version.h
/u01/obclient/include/mysql
/u01/obclient/include/mysql.h
/u01/obclient/include/mysql/client_plugin.h
/u01/obclient/include/mysql/plugin_auth.h
/u01/obclient/include/mysql/plugin_auth_common.h
/u01/obclient/include/mysqld_error.h
/u01/obclient/include/ob_complex.h
/u01/obclient/include/ob_cond.h
/u01/obclient/include/ob_full_link_trace.h
/u01/obclient/include/ob_load_balance.h
/u01/obclient/include/ob_object.h
/u01/obclient/include/ob_oralce_format_models.h
/u01/obclient/include/ob_protocol20.h
/u01/obclient/include/ob_rwlock.h
/u01/obclient/include/ob_thread.h
/u01/obclient/include/ob_thread_key.h
/u01/obclient/lib
/u01/obclient/lib/libobclnt.a
/u01/obclient/lib/libobclnt.so
/u01/obclient/lib/libobclnt.so.2
/u01/obclient/lib/libobclnt.so.2.2.6
/u01/obclient/lib/pkgconfig
/u01/obclient/lib/pkgconfig/libmariadb.pc
/u01/obclient/lib/plugin
/u01/obclient/lib/plugin/auth_gssapi_client.so
/u01/obclient/lib/plugin/dialog.so
/u01/obclient/lib/plugin/mysql_clear_password.so
/u01/obclient/lib/plugin/remote_io.so
/usr/lib/.build-id
/usr/lib/.build-id/0b
/usr/lib/.build-id/0b/6e62d75307e1f681faf63ac308c4890b42c326
/usr/lib/.build-id/50
/usr/lib/.build-id/50/168c7344fda63f66af809b178ba1985291178c
/usr/lib/.build-id/60
/usr/lib/.build-id/60/8ff0dd447cd98893ebde5217d404d4f9ed8ad1
/usr/lib/.build-id/c1
/usr/lib/.build-id/c1/3f6c6f8474f09b48443907df2389f058fb136e
/usr/lib/.build-id/d3
/usr/lib/.build-id/d3/cc58f06047faa64e5119b1742d2f3e7a9438ad
/usr/lib/.build-id/ea
/usr/lib/.build-id/ea/7c41ea02165eb86557838ccf8ee90c1029d496

```

### 安装 OBCI

通过如下命令安装。

```shell
#rpm -ivh obci-2.0.10-22024072517.el7.x86_64.rpm
warning: obci-2.0.10-22024072517.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 5ee0fb49: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:obci-2.0.10-22024072517.el7      ################################# [100%]

```

```shell
#rpm -qa|grep obci
obci-2.0.10-22024072517.el7.x86_64

```

```shell
#rpm -ql obci-2.0.10-22024072517.el7.x86_64
/u01/obclient
/u01/obclient/bin
/u01/obclient/bin/obci_dblink_check
/u01/obclient/lib
/u01/obclient/lib/libobci.a
/u01/obclient/lib/libobci.so
/u01/obclient/lib/libobci.so.2
/u01/obclient/lib/libobci.so.2.0.10

```

### 安装 ECOB

通过如下命令安装。

```shell
#rpm -ivh ecob-1.1.9-42024073014.el7.x86_64.rpm
warning: ecob-1.1.9-42024073014.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID 5ee0fb49: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
Updating / installing...
   1:ecob-1.1.9-42024073014.el7       ################################# [100%]

```

```shell
#rpm -qa|grep ecob
ecob-1.1.9-42024073014.el7.x86_64

```

```shell
#rpm -ql ecob-1.1.9-42024073014.el7.x86_64
/usr/lib/.build-id
/usr/lib/.build-id/2d
/usr/lib/.build-id/2d/20ca2af8e2e239dbfbe95045b77277eb7b9f3f
/usr/lib/.build-id/3a
/usr/lib/.build-id/3a/a08aa372dbb36376782d8856f45adc6ae323df
/usr/local/bin
/usr/local/bin/ecob
/usr/local/bin/modify_env.sh
/usr/local/bin/proc
/usr/local/include
/usr/local/include/datetime.h
/usr/local/include/decimal_ob.h
/usr/local/include/ecob-pthread-win32.h
/usr/local/include/ecob_config.h
/usr/local/include/ecob_informix.h
/usr/local/include/ecoberrno.h
/usr/local/include/ecoblib.h
/usr/local/include/ecobtype.h
/usr/local/include/ecpg_config.h
/usr/local/include/ecpglib.h
/usr/local/include/obtypes.h
/usr/local/include/obtypes_date.h
/usr/local/include/obtypes_error.h
/usr/local/include/obtypes_interval.h
/usr/local/include/obtypes_numeric.h
/usr/local/include/obtypes_timestamp.h
/usr/local/include/pg_config_ext.h
/usr/local/include/postgres_ext.h
/usr/local/include/sql3types.h
/usr/local/include/sqlca.h
/usr/local/include/sqlda-compat.h
/usr/local/include/sqlda-native.h
/usr/local/include/sqlda.h
/usr/local/include/sqltypes.h
/usr/local/lib64
/usr/local/lib64/libecob.so
/usr/local/lib64/libecob.so.6
/usr/local/lib64/libecob.so.6.12
/usr/local/src/ecob-examples
/usr/local/src/ecob-examples/Makefile
/usr/local/src/ecob-examples/connect.pc
/usr/local/src/ecob-examples/cursor.pc
/usr/local/src/ecob-examples/delete.pc
/usr/local/src/ecob-examples/dynamicSQL.pc
/usr/local/src/ecob-examples/example.pc
/usr/local/src/ecob-examples/prepare.pc
/usr/local/src/ecob-examples/struct.pc
/usr/local/src/ecob-examples/update.pc

```

### 配置 OCI

通过如下命令解压 `oracle-instantclient12.2-devel-12.2.0.1.0-1.x86_64.rpm`。 **注意**：x86 和 arm 服务器均可使用此安装包，按如下命令解压即可。

```shell
#rpm2cpio oracle-instantclient12.2-devel-12.2.0.1.0-1.x86_64.rpm | cpio -idmv
./usr/include/oracle/12.2/client64/ldap.h
./usr/include/oracle/12.2/client64/nzerror.h
./usr/include/oracle/12.2/client64/nzt.h
./usr/include/oracle/12.2/client64/occi.h
./usr/include/oracle/12.2/client64/occiAQ.h
./usr/include/oracle/12.2/client64/occiCommon.h
./usr/include/oracle/12.2/client64/occiControl.h
./usr/include/oracle/12.2/client64/occiData.h
./usr/include/oracle/12.2/client64/occiObjects.h
./usr/include/oracle/12.2/client64/oci.h
./usr/include/oracle/12.2/client64/oci1.h
./usr/include/oracle/12.2/client64/oci8dp.h
./usr/include/oracle/12.2/client64/ociap.h
./usr/include/oracle/12.2/client64/ociapr.h
./usr/include/oracle/12.2/client64/ocidef.h
./usr/include/oracle/12.2/client64/ocidem.h
./usr/include/oracle/12.2/client64/ocidfn.h
./usr/include/oracle/12.2/client64/ociextp.h
./usr/include/oracle/12.2/client64/ocikpr.h
./usr/include/oracle/12.2/client64/ocixmldb.h
./usr/include/oracle/12.2/client64/ocixstream.h
./usr/include/oracle/12.2/client64/odci.h
./usr/include/oracle/12.2/client64/oratypes.h
./usr/include/oracle/12.2/client64/ori.h
./usr/include/oracle/12.2/client64/orid.h
./usr/include/oracle/12.2/client64/orl.h
./usr/include/oracle/12.2/client64/oro.h
./usr/include/oracle/12.2/client64/ort.h
./usr/include/oracle/12.2/client64/xa.h
./usr/lib/oracle/12.2/client64/lib/libclntsh.so
./usr/lib/oracle/12.2/client64/lib/libclntshcore.so
./usr/lib/oracle/12.2/client64/lib/libocci.so
./usr/lib/oracle/12.2/client64/lib/ottclasses.zip
./usr/share/oracle/12.2/client64/admin/oraaccess.xsd
./usr/share/oracle/12.2/client64/demo/cdemo81.c
./usr/share/oracle/12.2/client64/demo/demo.mk
./usr/share/oracle/12.2/client64/demo/occidemo.sql
./usr/share/oracle/12.2/client64/demo/occidemod.sql
./usr/share/oracle/12.2/client64/demo/occidml.cpp
./usr/share/oracle/12.2/client64/demo/occiobj.cpp
./usr/share/oracle/12.2/client64/demo/occiobj.typ
./usr/share/oracle/12.2/client64/demo/oraaccess.xml
./usr/share/oracle/12.2/client64/demo/ott
./usr/share/oracle/12.2/client64/demo/setuporamysql.sh
4051 blocks

```

复制 OCI 头文件到 `/u01/obclient/include/` 目录下并查看。

```shell
cp -a ./usr/include/oracle/12.2/client64/* /u01/obclient/include/
ls -l /u01/obclient/include

```

### 配置 LD_LIBRARY_PATH

通过如下命令配置 `LD_LIBRARY_PATH`。

```shell
echo $LD_LIBRARY_PATH
vi ~/.bash_profile

```

添加如下内容。

```shell
export LD_LIBRARY_PATH=/u01/obclient/lib:/usr/local/lib64/:$LD_LIBRARY_PATH

```

执行如下命令使其生效并验证。

```shell
source ~/.bash_profile
echo $LD_LIBRARY_PATH

```

### 配置 TNS_ADMIN

以 `tnsnames.ora` 在如下目录为例。

```shell
cd /usr/local/src/ecob-examples

```

编辑 `tnsnames.ora`。

```shell
# vi tnsnames.ora

```

连接 `obclient -h10.10.20.20 -P2883 -uALVIN@oboraclegbk#obcluster -A -pxxx` 对应内容如下。

```shell
alvin =
 (DESCRIPTION=
   (ADDRESS=(PROTOCOL = TCP)(HOST = 10.10.20.20)(PORT = 2883))
   (CONNECT_DATA=
     (SERVICE_NAME=ALVIN))
)

```

**注**：`tnsnames.ora` 中 `=` 左边的 `alvin` (自定义，也可以使用其他名字) 区分大小写，`SERVICE_NAME` 后面的 `ALVIN` 不区分大小写。 通过如下命令配置 `TNS_ADMIN`。

```shell
echo $TNS_ADMIN
vi ~/.bash_profile

```

添加如下内容。

```shell
export TNS_ADMIN=/usr/local/src/ecob-examples/

```

```shell
source ~/.bash_profile
echo $TNS_ADMIN

```

### 编写测试用例

```shell
cd /usr/local/src/ecob-examples

```

`test.pc` 内容如下。

```shell
#include <stdio.h>

void myconnect(){
    EXEC SQL BEGIN DECLARE SECTION;
    char * username="ALVIN@oboraclegbk#obcluster";
    char * password="xxx";
    char * servicename="alvin";
    EXEC SQL END DECLARE SECTION;
    EXEC SQL CONNECT :username identified by :password using :servicename;
    if(sqlca.sqlcode !=0)
        printf("connect error\n");
    else
        printf("connetion successfull\n");
}

int main(){
    myconnect();
    EXEC SQL BEGIN DECLARE SECTION;
    char job[10];
    float salary;
    EXEC SQL END DECLARE SECTION;
    EXEC SQL DROP TABLE emp;
    EXEC SQL CREATE TABLE emp (ename VARCHAR2(20), sal INT, job VARCHAR2(20));
    EXEC SQL INSERT INTO emp VALUES ('ALVIN', 1000, 'ENG');
    EXEC SQL COMMIT WORK;
    EXEC SQL SELECT sal,job INTO :salary,:job FROM emp;
    printf("job:%s, salary:%6.2f!\n",job,salary);
    return 0;
}

```

**注**：此示例中 `servicename` 中的 `alvin` 区分大小写（同 `tnsnames.ora` 中 `=` 左边的 `alvin` 保持一致），用户名中的 `ALVIN` 不区分大小写。

通过如下命令编译并执行。

```shell
#ecob test.pc
#gcc -g -L /usr/local/lib64/ -L /u01/obclient/lib/ -lecob -lobci -I /u01/obclient/include -I /usr/local/include/ -o test test.c
#./test

```

正常输出结果如下。

```shell
#./test
connetion successfull
job:ENG      , salary:1000.00!

```

### Easy Connect 连接方式

除了配置 `TNS_ADMIN` + `tnsnames.ora` 的方式外，也支持类似 [Oracle Easy Connect](https://docs.oracle.com/en/database/oracle/oracle-database/18/ntcli/specifying-a-connection-by-using-the-easy-connect-naming-method.html) 连接的方式。 即 `test.pc` 中 `servicename` 改为如下 Easy Connect 连接方式，此时不依赖 `TNS_ADMIN` 和 `tnsnames.ora`。

```shell
char * servicename="10.10.20.20:2883/ALVIN";

```

**注**：此 `servicename` 中的 `ALVIN` 不区分大小写。 必要时，也可以使用此 Easy Connect 方式测试连接，以对比检查 `TNS_ADMIN` 和 `tnsnames.ora` 配置是否正确。

### 报错自助排查

#### 报错 1 - 编译时缺少 oci.h

```shell
#gcc -g -L /usr/local/lib64/ -L /u01/obclient/lib/ -lecob -lobci -I /usr/local/include/ -o test test.c
In file included from test.c:3:0:
/usr/local/include/ecoblib.h:23:10: fatal error: oci.h: No such file or directory
 #include "oci.h"
          ^~~~~~~
compilation terminated.

```

**解决方法**：参考本文档 **配置 OCI** 章节的步骤。

#### 报错 2 - 编译时缺少 libobclnt.so.2

**解决方法**：参考本文档 **安装 libobclient** 章节的步骤。

#### 报错 3 - 编译时缺少 libobci.so.20

当前测试版本无此报错。

如之前版本有如下报错。

```shell
# gcc -g -L /usr/local/lib64/ -L /u01/obclient/lib/ -lecob -lobci -I /u01/obclient/include -I /usr/local/include/ -o test test.c
/usr/bin/ld: warning: libobci.so.20, needed by /usr/local/lib64//libecob.so, not found (try using -rpath or -rpath-link)

```

**解决方法**：确认已安装 OBCI 后，可以创建软链接。

```shell
# cd /u01/obclient/lib/
# ln -s libobci.so.2.0.7 libobci.so.20

```

#### 报错 4 - 执行时报错 connect error

```shell
#./test
connect error
job:, salary:  0.00!

```

**解决方法**：参考本文档 **配置 TNS_ADMIN** 章节步骤，以及检查程序中数据库连接信息是否正确。 必要时，也可以使用 Easy Connect 方式测试连接，以对比检查 `TNS_ADMIN` 和 `tnsnames.ora` 配置是否正确。

#### 报错 5 - 执行时有 connetion successfull 但程序报错

```shell
#./test
connetion successfull
Segmentation fault (core dumped)

```

**解决方法**：数据库连接没有问题，建议排查程序问题。

#### 报错 6 - 与已安装的旧版本冲突

```shell
# rpm -ivh libobclient-2.2.6-42024052211.el7.x86_64.rpm
warning: libobclient-2.2.6-42024052211.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID b288a9d3: NOKEY
Verifying...                          ################################# [100%]
Preparing...                          ################################# [100%]
    file /u01/obclient/bin/mariadb_config from install of libobclient-2.2.6-42024052211.el7.x86_64 conflicts with file from package libobclient-2.1.2-20211201104607.el7.alios7.x86_64

```

**解决方法**：升级版本即可（如有安装 OceanBase 数据库 ODBC 等依赖 libobclient 的驱动，直接卸载旧版本会报错，所以可以采用升级版本的方法）。

```shell
rpm -Uvh libobclient-2.2.6-42024052211.el7.x86_64.rpm

```

## 适用版本

OceanBase 数据库 V3.2.x、V4.2.x 版本。

Previous

[如何手工配置 Chrony Server 和 Chrony Client](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000000933395)

Next

[OceanBase 数据库安装部署之磁盘初始化](https://www.oceanbase.com/knowledge-base/oceanbase-database-1000000003564245) ![有帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*y6ocSqN8cqsAAAAAAAAAAAAAARQnAQ)![无帮助](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*BG9IQJyLHF8AAAAAAAAAAAAAARQnAQ)![反馈](https://gw.alipayobjects.com/mdn/ob_asset/afts/img/A*eTWdQKCRKHwAAAAAAAAAAAAAARQnAQ)[AI](https://www.oceanbase.com/obi) 咨询热线
