search
HomeDatabaseMysql Tutorial如何创建自己的InstantClient包

IC介绍 许多人正在使用Oracle Instant Client,它提供一个部署基于OCI、OCCI、JDBC OCI应用容易和快速的方法。 通过添加更多的工具,Instant Client可以变成一个更加强大的工具,如下: 1. tnsping 2. sqlldr 3. tkprf 4. exp/imp 5. OCM 6. 你自己的工具 这

 

IC介绍

许多人正在使用Oracle Instant Client,它提供一个部署基于OCI、OCCI、JDBC OCI应用容易和快速的方法。

通过添加更多的工具,Instant Client可以变成一个更加强大的工具,如下:

1. tnsping

2. sqlldr

3. tkprf

4. exp/imp

5. OCM

6. 你自己的工具

这样做的主要优点是:

1. 安装是一件轻而易举的事情,只要解压即可完成。

2. 体积小,未压缩100MB到150MB或压缩50MB,它可以安装在USB盘上

3. 不涉及到SA(软件架构)

比较一个完整的Oracle安装需要大量的磁盘空间,而且还涉及到SA。

IC需求

1. 一个带有150MB+磁盘空间的Unix/Linux账号:

hadoop@192.168.8.162:/home/hadoop/oracle

2. 安装Oracle 11gR2的相同平台,一个具有读访问权限的账号:

root@192.168.8.192:/u01/product/oracle/11.2.0/db_1

IC安装

从Oracle官方网址下载安装包,下载网址: http://www.oracle.com/technetwork/cn/database/features/instant-client/index-097480.html

注:请根据操作系统版本下载相应的安装包,这里下载Linux X86-64安装包。

instantclient-basic-linux.x64-11.2.0.4.0.zip

instantclient-jdbc-linux.x64-11.2.0.4.0.zip

instantclient-sdk-linux.x64-11.2.0.4.0.zip

instantclient-sqlplus-linux.x64-11.2.0.4.0.zip

注:下载Instant Client时需要创建一个Oracle账号才能下载。

使用SSH客户端使用安装账号登录到服务器,在根目录下创建一个oracle目录:

$mkdir /home/hadoop/oracle

上传所有压缩包或至少basic和sqlplus两个包到你账号的根目录下oracle中。

解压到当前目录下完成安装。

$ cd /home/hadoop/oracle

$ unzipinstantclient-basic-linux.x64-11.2.0.4.0.zip

$ unzipinstantclient-sqlplus-linux.x64-11.2.0.4.0.zip

$ unzip instantclient-sdk-linux.x64-11.2.0.4.0.zip

$ unzip instantclient-jdbc-linux.x64-11.2.0.4.0.zip

解压完毕后会在当前目录下生成一个instantclient_11_2目录。

$ ll /home/hadoop/oracle/instantclient_11_2

IC配置

配置下面的环境变量到你的Shell配置文件中。

$ vi ~/.bashrc

跳到文件的末尾,添加下面这些环境变量:

export RACLE_IC_HOME=/home/hadoop/oracle/instantclient_11_2

exportORACLE_HOME=$ORACLE_IC_HOME

exportTNS_ADMIN=$ORACLE_IC_HOME

exportPATH=$PATH:$ORACLE_IC_HOME

exportLD_LIBRARY_PATH=$ORACLE_IC_HOME

exportCLASSPATH=$ORACLE_IC_HOME/ojdbc6.jar:./

$ source ~/. bashrc

或 $ . ~/.bashrc

注:如果需要让所有用户都能使用,需要把上面的配置添加/etc/profile中。

在$ORACLE_IC_HOME目录下创建一个tnsnames.ora文件:

$ vi /home/hadoop/oracle/instantclient_11_2/tnsnames.ora

orcl=(description=(address=(protocol=tcp)(host=192.168.8.161)(port=1521))(connect_data=(server=dedicated)(service_name=wcdma)))

ora =(DESCRIPTION =(ADDRESS_LIST =(ADDRESS =(PROTOCOL = TCP)(HOST = 192.168.8.161)(PORT = 1521)))(CONNECT_DATA =(SERVER =DEDICATED)(SERVICE_NAME = wcdma)))

SQL*Plus

$ sqlplus kqi/kqi@192.168.8.161:1521/wcdma

$ sqlplus kqi/kqi@orcl

 

SQL*Plus: Release 11.2.0.4.0 Production onThu Nov 20 14:01:49 2014

 

Copyright (c) 1982, 2013, Oracle. All rights reserved.

 

 

Connected to:

Oracle Database 11g Enterprise EditionRelease 11.2.0.2.0 - 64bit Production

With the Partitioning, OLAP, Data Miningand Real Application Testing options

 

SQL>

ERROR:

ORA-12154: TNS:could not resolve theconnect identifier specified

对于这种问题,排除添加的配置格式错误后。可能原因是读取的tnsnames.ora路径根本就不是$ORACLE_HOME/network/admin下。

注:tnsnames.ora文件的查找路径顺序为:

$HOME => $TNS_ADMIN => /etc =>$ORACLE_HOME/network/admin/。

 

现在我们已经有一个构建自己的Instant Client包的基础了。下面是Instant Client的核心文件(位于/home/hadoop/oracle/instantclient_11_2中):

1. libclntsh.so.11.1:客户端代码库

2. libociei.so:OCI InstantClient数据共享库

3. libnnz11.so:安全库

4. libocci.so.11.1:Oracle C++调用接口库

5. libocijdbc11.so:JDBC OCI库

6. ojdbc6/5.jar:JDBC驱动(OCI和Thin)

7. orai18n.jar:字符集转换和本地支持库

Tnsping

从安装Oracle的服务器上拷贝tnsping过来,执行命令:

$ cd /home/hadoop/oracle/instantclient_11_2

$ scp root@192.168.8.192:/u01/product/oracle/11.2.0/db_1/bin/tnsping./

 

现在让在IC安装服务器上尝试运行下它:

$ tnsping ora

 

TNS Ping Utility for Linux: Version11.2.0.4.0 - Production on 20-NOV-2014 14:30:21

 

Copyright (c) 1997, 2013, Oracle. All rights reserved.

 

Message 3511 not found; No message file forproduct=network, facility=TNSMessage 3512 not found; No message file forproduct=network, facility=TNSMessage 3513 not found; No message file forproduct=network, facility=TNSMessage 3509 not found; No message file forproduct=network, facility=TNS

运行后tnsping抱怨一些文件丢失,更具体的说一个消息文件丢失。现在,我们把该文件从Oracle安装服务器上拷贝过来,进入到instantclient_11_2目录:

$ mkdir -p network/mesg

$ cd network/mesg/

现在从安装Oracle服务上拷贝tnsus.msb文件到该目录中:

$ scp root@192.168.8.192:/u01/product/oracle/11.2.0/db_1/network/mesg/tnsus.msb ./

让我们再尝试一次tnsping,结果如下:

$ tnsping ora

 

TNS Ping Utility for Linux: Version11.2.0.4.0 - Production on 20-NOV-2014 14:49:54

 

Copyright (c) 1997, 2013, Oracle. All rights reserved.

 

Used parameter files:

 

 

Used TNSNAMES adapter to resolve the alias

Attempting to contact (DESCRIPTION=(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.8.161)(PORT =1521)))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = wcdma)))

OK (0 msec)

Sqlldr

本节将添加另外一个工具sqlldr。

首先,我们从安装Oracle的服务器上拷贝sqlldr到IC安装目录instantclient_11_2下。

$ cd /home/hadoop/oracle/instantclient_11_2

$ scproot@192.168.8.192:/u01/product/oracle/11.2.0/db_1/bin/sqlldr ./

尝试运行它:

$ sqlldr

Message 2100 not found; No message file forproduct=RDBMS, facility=ULMessage 2100 not found; No message file forproduct=RDBMS, facility=UL

首先我们需要在instantclient_11_2下创建rdbms/mesg目录。

$ cd /home/hadoop/oracle/instantclient_11_2

$ mkdir -p rdbms/mesg

$ cd rdbms/mesg

把ORACLE安装目录下rdmsb/mesg/ulus.msb拷贝到当前目录。

$ scp root@192.168.8.192:/u01/product/oracle/11.2.0/db_1/rdbms/mesg/ulus.msb./

现在,让我们再次尝试运行它。

$ sqlldr

 

SQL*Loader: Release 11.2.0.4.0 - Productionon Thu Nov 20 16:40:10 2014

 

Copyright (c) 1982, 2011, Oracle and/or itsaffiliates. All rights reserved.

 

 

Usage: SQLLDR keyword=value[,keyword=value,...]

 

Valid Keywords:

Exp/imp

从安装Oracle服务器上拷贝二进制文件过来。

$ cd /home/hadoop/oracle/instantclient_11_2

$ scp root@192.168.8.192:/u01/product/oracle/11.2.0/db_1/bin/imp ./
$ scp root@192.168.8.192:/u01/product/oracle/11.2.0/db_1/bin/exp ./

尝试运行imp和exp,结果如下:

$ imp

 

Message 100 not found; No message file forproduct=RDBMS, facility=IMP: Release 11.2.0.4.0 - Production on Thu Nov 2017:02:57 2014

 

Copyright (c) 1982, 2011, Orac

 

Invalid format of Import utility name

 

Verify that ORACLE_HOME is properly set

 

Import terminated unsuccessfully

 

IMP-00000: Message 0 not found; No messagefile for product=RDBMS, facility=IMP

$ exp

 

Message 206 not found; No message file forproduct=RDBMS, facility=EXP: Release 11.2.0.4.0 - Production on Thu Nov 20 17:03:392014

 

Copyright (c) 1982, 2011, Orac

 

Invalid format of Export utility name

 

Verify that ORACLE_HOME is properly set

 

Export terminated unsuccessfully

 

EXP-00000: Message 0 not found; No messagefile for product=RDBMS, facility=EXP

再从安装Oracle服务器上拷贝rdbms/mesg下的expus.msb和ipus.msb过来。

$ cd rdbms/mesg/

$ scproot@192.168.8.192:/u01/product/oracle/11.2.0/db_1/rdbms/mesg/impus.msb ./

$ scproot@192.168.8.192:/u01/product/oracle/11.2.0/db_1/rdbms/mesg/expus.msb ./

再次运行imp/exp工具错误提示消失,可以正常运行。

Tkprof

现在我们继续添加我最喜欢的工具tkprof。

从安装Oracle的服务器拷贝tkprof到instantclient_11_2目录下。

$ cd /home/hadoop/oracle/instantclient_11_2

$ scp root@192.168.8.192:/u01/product/oracle/11.2.0/db_1/bin/tkprof ./

$ mkdir -p oracore/mesg/

$ cd oracore/mesg/

$ scproot@192.168.8.192:/u01/product/oracle/11.2.0/db_1/oracore/mesg/lrmus.msb ./

使用示例:

$ tkprof test.trc test.out

Instant Client Bundle

现在,我们已经让所有工具都能正常工作。简单的使用工具压缩打包instantclient_11_2目录,这样你就获得你自己的Instant Client包。例如:

$ cd /home/hadoop/oracle

$ tar zcf instantclient_11_2.tar.gzintantclient_11_2

正如你所看到的,打包成的instant client带有tnsping,sqlldr, exp/imp,tkprof工具,这让IC更加的功能强大。

安装自定义的IC包步骤如下:

1. 上传到服务器上解压缩

2. 修改环境变量

$ vi ~/.bashrc

跳到文件的末尾,添加下面这些环境变量:

export ORACLE_IC_HOME=/instantclient_11_2

export ORACLE_HOME=$ORACLE_IC_HOME

export TNS_ADMIN=$ORACLE_IC_HOME

export PATH=$PATH:$ORACLE_IC_HOME

export LD_LIBRARY_PATH=$ORACLE_IC_HOME

exportCLASSPATH=$ORACLE_IC_HOME/ojdbc6.jar:./

$ source ~/. bashrc

或 $ . ~/.bashrc

3. 添加连接数据库的配置

$ vi $ORACLE_IC_HOME/tnsnames.ora

安装完成,现在就可以使用Instant Client中的工具啦!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How to Grant Permissions to New MySQL UsersHow to Grant Permissions to New MySQL UsersMay 09, 2025 am 12:16 AM

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

How to Add Users in MySQL: A Step-by-Step GuideHow to Add Users in MySQL: A Step-by-Step GuideMay 09, 2025 am 12:14 AM

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

MySQL: Adding a new user with complex permissionsMySQL: Adding a new user with complex permissionsMay 09, 2025 am 12:09 AM

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

MySQL: String Data Types and CollationsMySQL: String Data Types and CollationsMay 09, 2025 am 12:08 AM

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

MySQL: What length should I use for VARCHARs?MySQL: What length should I use for VARCHARs?May 09, 2025 am 12:06 AM

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.

MySQL BLOB : are there any limits?MySQL BLOB : are there any limits?May 08, 2025 am 12:22 AM

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

MySQL : What are the best tools to automate users creation?MySQL : What are the best tools to automate users creation?May 08, 2025 am 12:22 AM

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

MySQL: Can I search inside a blob?MySQL: Can I search inside a blob?May 08, 2025 am 12:20 AM

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment