After you obtain the installation packages of OceanBase Connector/ODBC for Linux, perform the following operations to install and configure OceanBase Connector/ODBC.
Install OceanBase Connector/ODBC
- Check whether OceanBase Connector/ODBC of any version has been installed and query the version.
rpm -qa | grep odbc
rpm -qa | grep obclient
- If you want to install another version, run the following commands to delete the current version.
rpm -e ob-connector-odbc-<version_no>.rpm
rpm -e libobclient-<version_no>.rpm
rpm -e ob-unixodbc-<version_no>.rpm
- Install the RPM packages of OceanBase Connector/ODBC of the target version.
sudo rpm -ivh ob-connector-odbc-<version_no>.rpm
sudo rpm -ivh ob-unixodbc-<version_no>.rpm
sudo rpm -ivh libobclient-<version_no>.rpm
- Check whether the version is correct.
rpm -qa | grep odbc
rpm -qa | grep obclient
Install the required Libtool tool based on the environment.
yum install libtool-ltdl-devel
Configure environment variables
- Put the
odbc.iniconfiguration file in the/etc/odbc.inidirectory. You can also put the file in a custom directory and set the environment variable corresponding to the file to the custom directory.
$sudo vim /etc/odbc.ini
[ODBC Data Sources]
data_source_name = OBDSN
[OBDSN]
Driver=Oceanbase
Description = OceanBase Driver DSN
SERVER = xxx.xxx.xxx.xxx
PORT = 10003
USER = tester@oracle
Password = 1******
Database = unittests
OPTION = 4
charset=UTF8
[OBDSNMYSQL]
Driver=Oceanbase
Description = OceanBase Driver DSN
SERVER = xxx.xxx.xxx.xxx
PORT = 10003
USER = tester@sys
Password = 1******
Database = unittests
OPTION = 4
charset=UTF8
The following table describes the parameters in the configuration file.
| Parameter | Description |
|---|---|
| Driver | The driver in the odbcinst.ini configuration file, which is user-defined. |
| Description | The description of the driver. |
| SERVER | The IP address of the database. |
| PORT | The port number of the database. |
| USER | The username that you use to log on to the database. |
| Password | The password that you use to log on to the database. |
| Database | The name of the database. |
| OPTION | The configuration option. Valid value: OPTION=4, which indicates to enable logging. |
| charset | The character set of the database. Default value: UTF8. |
- Put the
odbcinst.iniconfiguration file in the/etc/odbcinst.inidirectory.
$sudo vim /etc/odbcinst.ini
[Oceanbase]
Description = ODBC for Oceanbase
Driver = /u01/ob-connector-odbc/lib64/mariadb/libobodbc.so
- Set environment variables.
$export ODBCSYSINI=/etc
$export ODBCINI=/etc/odbc.ini
$export LD_LIBRARY_PATH=/u01/unix-odbc/lib:/u01/obclient/lib:/u01/ob-connector-odbc:$LD_LIBRARY_PATH
- Run the
odbcinst -jcommand to check whether the environment variables are correct. Example:
$/u01/unix-odbc/bin/odbcinst -j
unixODBC 2.3.0
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /etc/odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
- Check whether the environment dependencies are correct.
$cd /u01/ob-connector-odbc/lib64/mariadb
[root@eefdc4281eb7 mariadb]# ldd /u01/ob-connector-odbc/lib64/mariadb/libobodbc.so
linux-vdso.so.1 => (0x00007fffd4bf0000)
libobclnt.so.20 => /u01/mysql/lib/libobclnt.so.20 (0x00007f62a8df2000)
libodbcinst.so.2 => /u01/unix-odbc/lib/libodbcinst.so.2 (0x00007f62a8bdd000)
libm.so.6 => /lib64/libm.so.6 (0x00007f62a88db000)
libc.so.6 => /lib64/libc.so.6 (0x00007f62a850d000)
libdl.so.2 => /lib64/libdl.so.2 (0x00007f62a8309000)
libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f62a80ed000)
libltdl.so.7 => /lib64/libltdl.so.7 (0x00007f62a7ee3000)
/lib64/ld-linux-x86-64.so.2 (0x00007f62a92c4000)
# Make sure that the dependency of libobclnt.so.20 matches the libobclient-xxx.rpm package installed.
Test connectivity
ISQL connectivity test
Tools related to the driver manager are stored in the /u01/unix-odbc directory. Run the connection command and check whether the connection succeeds.
$sudo vim /u01/unix-odbc/bin/isql -v OBDSN
+-------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+-------------------------------+
SQL>
Compile a C++ test program
g++ -I /u01/unix-odbc/include/ test.cpp -lobodbc -o test