如何在 Mac 上安装 Oracle Instant Client?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37711482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 01:06:52  来源:igfitidea点击:

How to install Oracle Instant Client on a Mac?

oraclemacosoracle12cinstantclient

提问by Ben

How to install Oracle Instant Client Version 12.1.0.2 (64-bit) on a Mac (OS X 10.11.5)

如何在 Mac (OS X 10.11.5) 上安装 Oracle Instant Client 版本 12.1.0.2(64 位)

I have downloaded version 12.1.0.2 (64-bit) version and unzipped the file.

我已经下载了 12.1.0.2(64 位)版本并解压了文件。

I now have the following files under /downloads/instantclient:

我现在在 /downloads/instantclient 下有以下文件:

libclntsh.dylib.12.1
libclntshcore.dylib.12.1
libnnz12.dylib
libocci.dylib.12.1
libociei.dylib
libocijdbc12.dylib
libons.dylib
liboramysql12.dylib
ojdbc6.jar
ojdbc7.jar
uidrvci
xstreams.jar
adrci
BASIC_README
genezi

I don't have the slightest idea how to go from this to a working version of Instant Client so I can connect to a db from the CLI. The instructions on Oracles website seem to be overly complicated.

我完全不知道如何从这个转换到 Instant Client 的工作版本,以便我可以从 CLI 连接到数据库。Oracles 网站上的说明似乎过于复杂。

I have found a few blogs detailing the installation method, but they all seem to be from previous version of Instant Client. Out of desperation, I downloaded a previous version of Instant Client, but still seemed to be missing files referred to in the tutorial.

我找到了一些详细介绍安装方法的博客,但它们似乎都来自早期版本的 Instant Client。无奈之下,我下载了以前版本的 Instant Client,但似乎仍然缺少教程中提到的文件。

Does anyone know how I can get Oracle Instant Client on my Mac?

有谁知道如何在我的 Mac 上获得 Oracle Instant Client?

回答by Alex Poole

There are multiple files available for download. From the files you listed you have only downloaded and unzipped the 'basic' package.

多个文件可供下载。从您列出的文件中,您只下载并解压缩了“基本”包。

To run the CLI (by which I assume you mean SQL*Plus) you need that package as well - the fourth in the list, titled "Instant Client Package - SQL*Plus: Additional libraries and executable for running SQL*Plus with Instant Client".

要运行 CLI(我假设您指的是 SQL*Plus),您还需要该包 - 列表中的第四个,标题为“Instant Client Package - SQL*Plus:用于使用 Instant Client 运行 SQL*Plus 的附加库和可执行文件” ”。

The packages are arranged such that if you unzip all the ones you need from the same place they all put their files in the same directory. Unfortunately that doesn't quite work if you use Safari and have it set to open certain downloaded files; each zip file is expanded into a separate folder, with incremented names. And it deletes the zip files afterwards.

这些包是这样安排的,如果你从同一个地方解压你需要的所有包,它们都会把它们的文件放在同一个目录中。不幸的是,如果您使用 Safari 并将其设置为打开某些下载的文件,则这不太有效;每个 zip 文件都扩展到一个单独的文件夹中,名称递增。之后它会删除 zip 文件。

You can either disable that automatic unzipping and do it manually, or copy the files from the individual folders into a common one.

您可以禁用自动解压缩并手动执行,也可以将文件从各个文件夹复制到一个公共文件夹中。

You may also need to create a symbolic link for the main client library; from inside that folder (in Terminal) you would do:

您可能还需要为主客户端库创建一个符号链接;从该文件夹内(在终端中),您将执行以下操作:

ln -s libclntsh.dylib.12.1 libclntsh.dylib

You can put that combined folder anywhere you like. You then need to add the full path to that folder to your PATH and environment variable - you can add that to your .bash_profile so you don't need to do it manually.

您可以将该组合文件夹放在您喜欢的任何位置。然后,您需要将该文件夹的完整路径添加到您的 PATH 和环境变量中 - 您可以将其添加到您的 .bash_profile 中,这样您就无需手动执行此操作。

Once you've done that you can execute sqlplusfrom anywhere.

完成后,您可以sqlplus从任何地方执行。

So to summarise:

所以总结一下:

  1. If you're using Safari, disable automatic opening of the zip files; from Safari->Preferences->General untick the 'Open "safe" files after downloading' checkbox.

  2. Downloadinstantclient-basic-macos.x64-12.1.0.2.0.zip and instantclient-sqlplus-macos.x64-12.1.0.2.0.zip

  3. In Terminal go to your Downloads directory.

  4. Unzip both files:

    MacBook:Downloads alex$ unzip instantclient-basic-macos.x64-12.1.0.2.0.zip
    Archive:  instantclient-basic-macos.x64-12.1.0.2.0.zip
      inflating: instantclient_12_1/BASIC_README  
      inflating: instantclient_12_1/adrci  
      inflating: instantclient_12_1/genezi  
      inflating: instantclient_12_1/libclntsh.dylib.12.1  
      inflating: instantclient_12_1/libclntshcore.dylib.12.1  
      inflating: instantclient_12_1/libnnz12.dylib  
      inflating: instantclient_12_1/libocci.dylib.12.1  
      inflating: instantclient_12_1/libociei.dylib  
      inflating: instantclient_12_1/libocijdbc12.dylib  
      inflating: instantclient_12_1/libons.dylib  
      inflating: instantclient_12_1/liboramysql12.dylib  
      inflating: instantclient_12_1/ojdbc6.jar  
      inflating: instantclient_12_1/ojdbc7.jar  
      inflating: instantclient_12_1/uidrvci  
      inflating: instantclient_12_1/xstreams.jar  
    MacBook:Downloads alex$ unzip instantclient-sqlplus-macos.x64-12.1.0.2.0.zip
    Archive:  instantclient-sqlplus-macos.x64-12.1.0.2.0.zip
      inflating: instantclient_12_1/SQLPLUS_README  
      inflating: instantclient_12_1/glogin.sql  
      inflating: instantclient_12_1/libsqlplus.dylib  
      inflating: instantclient_12_1/libsqlplusic.dylib  
      inflating: instantclient_12_1/sqlplus  
    
  5. Optionally rename and/or move the instantclient_12_1directory to somewhere more permanent.

  6. Add the location to your path in your current session, and also in your shell profile/resource file to make it take effect on every login:

     export PATH=$HOME/Downloads/instantclient_12_1:$PATH
    
  7. Enjoy.

    MacBook:Downloads alex$ export PATH=$HOME/Downloads/instantclient_12_1:$PATH
    MacBook:Downloads alex$ which sqlplus
    /Users/alex/Downloads/instantclient_12_1/sqlplus
    MacBook:Downloads alex$ sqlplus
    
    SQL*Plus: Release 12.1.0.2.0 Production on Thu Jun 9 16:29:49 2016
    
    Copyright (c) 1982, 2016, Oracle.  All rights reserved.
    
    Enter user-name: 
    
  1. 如果您使用 Safari,请禁用自动打开 zip 文件;从 Safari-> 首选项-> 常规取消勾选“下载后打开“安全”文件”复选框。

  2. 下载instantclient-basic-macos.x64-12.1.0.2.0.zip和instantclient-sqlplus-macos.x64-12.1.0.2.0.zip

  3. 在终端中转到您的下载目录。

  4. 解压两个文件:

    MacBook:Downloads alex$ unzip instantclient-basic-macos.x64-12.1.0.2.0.zip
    Archive:  instantclient-basic-macos.x64-12.1.0.2.0.zip
      inflating: instantclient_12_1/BASIC_README  
      inflating: instantclient_12_1/adrci  
      inflating: instantclient_12_1/genezi  
      inflating: instantclient_12_1/libclntsh.dylib.12.1  
      inflating: instantclient_12_1/libclntshcore.dylib.12.1  
      inflating: instantclient_12_1/libnnz12.dylib  
      inflating: instantclient_12_1/libocci.dylib.12.1  
      inflating: instantclient_12_1/libociei.dylib  
      inflating: instantclient_12_1/libocijdbc12.dylib  
      inflating: instantclient_12_1/libons.dylib  
      inflating: instantclient_12_1/liboramysql12.dylib  
      inflating: instantclient_12_1/ojdbc6.jar  
      inflating: instantclient_12_1/ojdbc7.jar  
      inflating: instantclient_12_1/uidrvci  
      inflating: instantclient_12_1/xstreams.jar  
    MacBook:Downloads alex$ unzip instantclient-sqlplus-macos.x64-12.1.0.2.0.zip
    Archive:  instantclient-sqlplus-macos.x64-12.1.0.2.0.zip
      inflating: instantclient_12_1/SQLPLUS_README  
      inflating: instantclient_12_1/glogin.sql  
      inflating: instantclient_12_1/libsqlplus.dylib  
      inflating: instantclient_12_1/libsqlplusic.dylib  
      inflating: instantclient_12_1/sqlplus  
    
  5. 可选择重命名和/或将instantclient_12_1目录移动到更永久的地方。

  6. 将该位置添加到当前会话中的路径,以及 shell 配置文件/资源​​文件中,以使其在每次登录时生效:

     export PATH=$HOME/Downloads/instantclient_12_1:$PATH
    
  7. 享受。

    MacBook:Downloads alex$ export PATH=$HOME/Downloads/instantclient_12_1:$PATH
    MacBook:Downloads alex$ which sqlplus
    /Users/alex/Downloads/instantclient_12_1/sqlplus
    MacBook:Downloads alex$ sqlplus
    
    SQL*Plus: Release 12.1.0.2.0 Production on Thu Jun 9 16:29:49 2016
    
    Copyright (c) 1982, 2016, Oracle.  All rights reserved.
    
    Enter user-name: 
    


El Capitan added system integrity protection (SIP), and one side effect of that is that exporting DYLD_LIBRARY_PATH doesn't work. That could affect running SQL*Plus from a shell script, for example. There are workaroundsfor the 11g instant client. The installation notes at the bottom of the download page have changed since I last did this, and it now says to hard link the library files to the user's ~/libdirectory to avoid that issue. Fortunately it looks like you don't need to worry about that with the 12c client - they've fixed the way it's built.

El Capitan 添加了系统完整性保护 (SIP),其副作用之一是导出 DYLD_LIBRARY_PATH 不起作用。例如,这可能会影响从 shell 脚本运行 SQL*Plus。有适用于 11g 即时客户端的解决方法。自从我上次这样做以来,下载页面底部的安装说明发生了变化,现在它说将库文件硬链接到用户~/lib目录以避免该问题。幸运的是,看起来您无需为 12c 客户端担心这个问题——他们已经修复了它的构建方式。

回答by dengApro

HomeBrew saved me. I do not figure out the environment path.

HomeBrew 救了我。我不知道环境路径。

1. Download the two files below fromhttp://www.oracle.com/technetwork/topics/intel-macsoft-096467.html.

1. 从http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html下载以下两个文件

This is necessary because of Oracle licenses.

由于 Oracle 许可,这是必要的。

instantclient-basic-macos.x64–11.2.0.4.0.zipand instantclient-sqlplus-macos.x64–11.2.0.4.0.zip

instantclient-basic-macos.x64–11.2.0.4.0.zipinstantclient-sqlplus-macos.x64–11.2.0.4.0.zip

Put the files in ~/Library/Caches/Homebrew

把文件放进去 ~/Library/Caches/Homebrew



PS:

PS:

in the latest versions of HomeBrew replace the above location ~/Library/Caches/HomeBrewwith ~/Library/Caches/HomeBrew/downloads.

And also rename the downloaded files with the names suggested by HomeBrew.

Thanks to @manuka_m

在自制软件的最新版本替换上述地点~/Library/Caches/HomeBrew~/Library/Caches/HomeBrew/downloads

并使用 HomeBrew 建议的名称重命名下载的文件。

感谢@manuka_m



2. Next run the following commands

2.接下来运行以下命令

$ brew tap InstantClientTap/instantclient

$ brew install instantclient-basic

$ brew install instantclient-sqlplus

$ brew tap InstantClientTap/instantclient

$ brew install instantclient-basic

$ brew install instantclient-sqlplus

Originated from Joost van Wollingen's doc

源自Joost van Wollingen 的文档

回答by Janusz

Using Homebrew(https://brew.sh/) simple as that:

使用Homebrew( https://brew.sh/) 就这么简单:

$ brew tap InstantClientTap/instantclient
$ brew install instantclient-basic
$ brew install instantclient-sqlplus

No additional libs needed in my case. Depending on your shell - rehashcould be needed.

在我的情况下不需要额外的库。取决于您的外壳 -rehash可能需要。

回答by Punnerud

Within SQLdeveloper you will find SQLplus, that works out of the box like on Windows.

在 SQLdeveloper 中,您会发现 SQLplus,它像在 Windows 上一样开箱即用。

SQLDeveloper example

SQLDeveloper 示例

(Should start like this)

(应该是这样开始的)

If you move the app under Application and manage to start up the SQLdeveloper-client you cant fint it here, called sql:

如果您将应用程序移动到应用程序下并设法启动 SQLdeveloper-client,您将无法在此处找到它,称为 sql:

/Applications/SQLDeveloper.app/Contents/Resources/sqldeveloper/sqldeveloper/bin/sql

To directly login, run sql and exit:

直接登录,运行sql退出:

sql username/password@ADDRESS_TO_DB:1521/SID @/path/to/your/pls_file_containing_sql/test.pls

Remember to include 'exit;' at the end of your pls-file.

记住包括'exit;' 在你的 pls 文件的末尾。