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
MySQL's Role: Databases in Web ApplicationsMySQL's Role: Databases in Web ApplicationsApr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

MySQL: Building Your First DatabaseMySQL: Building Your First DatabaseApr 17, 2025 am 12:22 AM

The steps to build a MySQL database include: 1. Create a database and table, 2. Insert data, and 3. Conduct queries. First, use the CREATEDATABASE and CREATETABLE statements to create the database and table, then use the INSERTINTO statement to insert the data, and finally use the SELECT statement to query the data.

MySQL: A Beginner-Friendly Approach to Data StorageMySQL: A Beginner-Friendly Approach to Data StorageApr 17, 2025 am 12:21 AM

MySQL is suitable for beginners because it is easy to use and powerful. 1.MySQL is a relational database, and uses SQL for CRUD operations. 2. It is simple to install and requires the root user password to be configured. 3. Use INSERT, UPDATE, DELETE, and SELECT to perform data operations. 4. ORDERBY, WHERE and JOIN can be used for complex queries. 5. Debugging requires checking the syntax and use EXPLAIN to analyze the query. 6. Optimization suggestions include using indexes, choosing the right data type and good programming habits.

Is MySQL Beginner-Friendly? Assessing the Learning CurveIs MySQL Beginner-Friendly? Assessing the Learning CurveApr 17, 2025 am 12:19 AM

MySQL is suitable for beginners because: 1) easy to install and configure, 2) rich learning resources, 3) intuitive SQL syntax, 4) powerful tool support. Nevertheless, beginners need to overcome challenges such as database design, query optimization, security management, and data backup.

Is SQL a Programming Language? Clarifying the TerminologyIs SQL a Programming Language? Clarifying the TerminologyApr 17, 2025 am 12:17 AM

Yes,SQLisaprogramminglanguagespecializedfordatamanagement.1)It'sdeclarative,focusingonwhattoachieveratherthanhow.2)SQLisessentialforquerying,inserting,updating,anddeletingdatainrelationaldatabases.3)Whileuser-friendly,itrequiresoptimizationtoavoidper

Explain the ACID properties (Atomicity, Consistency, Isolation, Durability).Explain the ACID properties (Atomicity, Consistency, Isolation, Durability).Apr 16, 2025 am 12:20 AM

ACID attributes include atomicity, consistency, isolation and durability, and are the cornerstone of database design. 1. Atomicity ensures that the transaction is either completely successful or completely failed. 2. Consistency ensures that the database remains consistent before and after a transaction. 3. Isolation ensures that transactions do not interfere with each other. 4. Persistence ensures that data is permanently saved after transaction submission.

MySQL: Database Management System vs. Programming LanguageMySQL: Database Management System vs. Programming LanguageApr 16, 2025 am 12:19 AM

MySQL is not only a database management system (DBMS) but also closely related to programming languages. 1) As a DBMS, MySQL is used to store, organize and retrieve data, and optimizing indexes can improve query performance. 2) Combining SQL with programming languages, embedded in Python, using ORM tools such as SQLAlchemy can simplify operations. 3) Performance optimization includes indexing, querying, caching, library and table division and transaction management.

MySQL: Managing Data with SQL CommandsMySQL: Managing Data with SQL CommandsApr 16, 2025 am 12:19 AM

MySQL uses SQL commands to manage data. 1. Basic commands include SELECT, INSERT, UPDATE and DELETE. 2. Advanced usage involves JOIN, subquery and aggregate functions. 3. Common errors include syntax, logic and performance issues. 4. Optimization tips include using indexes, avoiding SELECT* and using LIMIT.

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment