Linux uses unixODBC to connect to the Oracle database-my remarks

Original address: https://blog.csdn.net/guotianqing/article/details/78886622

related articles

1. Use unixODBC to connect to the Oracle database configuration under Linux- https://blog.csdn.net/lichangzai/article/details/40304077

2, using the method of connection configurations UNIXODBC ORACLE database ---- https://www.cnblogs.com/young525/p/5873744.html

3. Configure Unix ODBC on Linux to connect to Oracle database- https://www.eygle.com/archives/2005/01/linuxeieaeoeaun.html

4. Have used unixODBC to access oracle11gR2 database under linux---- http://blog.sina.com.cn/s/blog_48c49d5d01017z1b.html

5. Cannot find libclntsh.so.11.1 error solution when executing Oracle program under root---- https://blog.csdn.net/iw1210/article/details/8850335

6. Problems encountered-DBI's ODBC error report error when running the perl script: [unixODBC][Driver Manager]Data source name not found, and no default---- https://blog.csdn.net/ zzq900503/article/details/17352639

7、[IM002][unixODBC][Driver Manager]Data source name not found, and no default driver specified message when attemting to connect via isql----https://stackoverflow.com/questions/34369436/im002unixodbcdriver-managerdata-source-name-not-found-and-no-default-driv

8. Solve the problem that the .so library file cannot be found under Linux- https://blog.csdn.net/csdlwzy/article/details/84566401

9, zabbix odbc connect to oracle error libsqora.so.XX.1 can not find the solution---- https: //blog.csdn.net/su377486/article/details/109064604

10. The unixODBC connection is unsuccessful---- https://bbs.csdn.net/topics/390566189

11、ORA-12541:TNS:no listener 解决方法----https://blog.csdn.net/qq_44161999/article/details/105067346?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-1.control&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromBaidu-1.control

I. Overview

ODBC overview

ODBC (Open Database Connectivity) provides a standard API (application programming interface) method to access DBMS (Database Management System). These APIs use SQL to accomplish most of their tasks. ODBC itself also provides support for the SQL language, and users can directly send SQL statements to ODBC. The designers of ODBC strive to make it have the greatest independence and openness: it has nothing to do with specific programming languages, has nothing to do with specific database systems, and has nothing to do with specific operating systems. Microsoft released the world's first ODBC product in the form of a DLL set in 1993, and it has now become a component of the database in the Microsoft Open Services Architecture (WOSA, Windows Open Services Architecture). Microsoft's ODBC product is actually an ODBC driver manager, providing an ODBC application to a certain ODBC driver interface.

The ODBC interface is defined as follows:

  • ODBC function call library through which applications can connect to data sources, execute SQL commands and retrieve results
  • SQL grammar based on SQL-99 specification
  • A set of standard error codes
  • A standard way to connect and log in to the data source
  • Standard description of data types

The composition of the ODBC model

The model composition of ODBC is shown in the figure below. ODBC applications call the driver manager through the ODBC API. The driver manager can be either Microsoft driver manager or unixODBC driver manager. The driver manager also calls the ODBC driver through the ODBC API, and the ODBC driver uses the database API to connect to the database through network communication.

The composition of the ODBC module

Oracle ODBC driver

Oracle ODBC Driver uses Oracle Call Interface (Oracle Call Interface) client and server software to submit requests and receive responses from data sources. The Oracle network service communication protocol is used to communicate between the OCI client and the Oracle server. The Oralce ODBC driver is responsible for converting between ODBC SQL syntax and the syntax that can access the data source, and the communication is carried out normally. The driver architecture of Oracle ODBC is shown in the figure below.

Write picture description here

Two, download and install unixODBC

Download from the official address  http://www.unixodbc.org/download.html
Download file: unixODBC-2.3.4.tar.gz
Installation:

./configure --prefix=/usr/local/unixODBC --sysconfdir=/etc 
#默认安装路径为  /usr/local,通过 --prefix改变
#默认odbcinst安装在 {prefix}/etc,通过--sysconfdir改变到指定路径
make 
make install
  • 1
  • 2
  • 3
  • 4
  • 5

The options and descriptions of ./configure are as follows

option description
–prefix This defines where you want to install unixODBC. If you do not specify this it will default to /usr/local. If you do not want unixODBC all under a single directory you can use other configure options like –bindir, –sbindir etc for finer control.
–sysconfdir This defines where you want unixODBC configuration files to be stored. This defaults to /etc. The configuration files affected are odbcinst.ini (where ODBC drivers are defined), the system odbc.ini (where system data sources are defined) and ODBCDataSources (where system file DSNs are stored).
–enable-gui The default is “yes” if QT is found. If you want to build the GUI ODBC Administrator, odbctest and DataManager set this to “yes”(e.g. –enable-gui=yes). You will need QT libraries and header files to build the GUI components (see later). You should probably also set –with-x. NOTE In unixODBC 2.3.0, the default for –enable-drivers was changed to “no” and the GUI components were moved into a new project.
–enable-threads The default is “yes” if thread-support is found on your machine. All modern Linuxes will have pthreads support in glibc so it is probably best to leave this to default.
–enable-readline The default is “yes” if libreadline and its headers are found on your machine. This principally only affects unixODBC isql program. If readline support is found then you can edit text entered at the SQL prompt in isql.
–enable-drivers The default is “yes”. When enabled this will build all the ODBC drivers included with unixODBC. This includes MySQL, Postgres, MiniSQL and a text file driver.
–enable-iconv This defaults to “yes” if libiconv and its header files are found on your machine. If you build with iconv and access then unixODBC can do Unicode translations.

Three, download and install oracle ODBC Driver

The official download address is  http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html to
download the file:

instantclient-basic-linux.x64-11.2.0.3.0.zip
instantclient-odbc-linux.x64-11.2.0.3.0.zip

installation:

unzip instantclient-basic-linux.x64-11.2.0.3.0.zip
unzip instantclient-odbc-linux.x64-11.2.0.3.0.zip
#注意,上述两个文件解压到同一目录下。
chmod 775 odbc_update_ini.sh
./odbc_update_ini.sh /usr/local
#没有提示表示安装成功

#odbc_update_ini.sh参数说明:
#参数1:unixODBC DM安装路径。
#参数2:驱动安装的绝对路径(可选)。默认为运行脚本的路径。
#参数3:驱动名(可选),默认为Oracle 11g ODBC driver。
#参数4:数据源名称(可选),默认为OracleODBC-11g。

#运行完成后将添加一个DNS条目到$HOME/.odbc.ini , <DriverManager_HOME>/etc/odbcinst.ini,名称为:OracleODBC-11g
#修改odbc目录的权限:
chown -R 775 /opt/odbc
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

Fourth, configure environment variables

vi /etc/profile

Join

export ORACLE_HOME=/opt/oracle 
export LD_LIBRARY_PATH=/opt/oracle/lib
  • 1
  • 2

Make the setting effective immediately

source /etc/profile

Five, configure the listener and network environment

Because the oracle database is not installed locally, you need to get three files from the directory where the oracle database is installed.

[root@localhost admin]# pwd 
/opt/oracle/network/admin 
[root@localhost admin]# ls 
 listener.ora  sqlnet.ora  tnsnames.ora #就这三个文件,放到这个目录下 
  • 1
  • 2
  • 3
  • 4

Six, edit the configuration file

tnsnames.ora file

BOSSDATA = 
  (DESCRIPTION = 
    (ADDRESS = (PROTOCOL = TCP)(HOST =192.168.1.107)(PORT = 1521))  #192.168.1.107  IP地址   ,端口号:1521 
    (CONNECT_DATA = 
      (SERVER = DEDICATED) 
      (SERVICE_NAME = bossdata)                                   #bossdata  全局数据名 
    ) 
  ) 

EXTPROC_CONNECTION_DATA = 
  (DESCRIPTION = 
    (ADDRESS_LIST = 
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) 
    ) 
    (CONNECT_DATA = 
      (SID = PLSExtProc) 
      (PRESENTATION = RO) 
    ) 
  ) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

listener.ora file

SID_LIST_LISTENER = 
  (SID_LIST = 
    (SID_DESC = 
      (SID_NAME = PLSExtProc) 
      (ORACLE_HOME = \opt\oracle)#注意,这个是刚才配置的$ORACLE_HOME 
      (PROGRAM = extproc) 
    ) 
  ) 

LISTENER = 
  (DESCRIPTION_LIST = 
    (DESCRIPTION = 
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1)) 
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.107)(PORT = 1521))      #这个上面有说明 
    ) 
  ) 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

Seven, check the drive configuration

/usr/local/etc/odbcinst.ini file

[Oracle 11g ODBC driver]
Description     = Oracle ODBC driver for Oracle 11g
Driver          = /u01/app/ora11g/product/11.2.0/db_1/odbc/utl/libsqora.so.11.1
Setup           =
FileUsage       =
CPTimeout       =
CPReuse         = 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

8. Test

testing method:

isql <data source name> <user name> <password> -v

[root@bakdbserver ~]# isql OracleODBC-11g bi bi -v
+---------------------------------------+
| Connected!                            |
|                                       |
| sql-statement                         |
| help [tablename]                      |
| quit                                  |
|                                       |
+---------------------------------------+
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

The test shows that the connection to the database is successful.


Reference materials:
http://www.unixodbc.org/download.html
http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
https://www.easysoft.com/developer/interfaces /odbc/linux.html#introduction
The configuration of connecting to the Oracle database with unixODBC under Linux  http://blog.csdn.net/lichangzai/article/details/40304077
linux installs the Oracle client (instantclient) separately  http://blog.csdn .net/caomiao2006/article/details/11901123

 

//=========================================================

My note::

1>odbcinst -j-----------Check the file path used by odbc.ini+odbcinst.ini through this command! ! !

2> locate libclntsh.so.11.1

3>ldd  /usr/local/lib/libsqora.so.11.1

4>isql -v ORCL  username password

5> cat /etc/profile

 

 

 

 

 

 

Guess you like

Origin blog.csdn.net/xqhrs232/article/details/113244873