在如下网址下载Oracle Instant Client:
https://www.oracle.com/database/technologies/instant-client/macos-intel-x86-downloads.html
下载文件,需要登陆才能下载:
instantclient-basic-macos.x64-11.2.0.4.0.zip instantclient-sqlplus-macos.x64-11.2.0.4.0.zip
解压文件到你的目录,如:~/oracle/instantclient_11_2
设置环境变量
cat << 'EOF' >> ~/.zprofile # Oracle Client export ORACLE_HOME=~/oracle/instantclient_11_2 export DYLD_LIBRARY_PATH=$ORACLE_HOME:$PATH export SQLPATH=$ORACLE_HOME export PATH=$DYLD_LIBRARY_PATH:$ORACLE_HOME:$SQLPATH:$PATH EOF . ~/.zprofile
建立tnsnames.ora文件
mkdir -p $ORACLE_HOME/network/admin/ vi $ORACLE_HOME/network/admin/tnsnames.ora
XE = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 127.0.01)(PORT = 1521)) ) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = XE) ) )
Mac还有关闭Gatekeeper,否则会报错“macOS无法验证此App不包含恶意软件”。
sudo spctl --master-disable
执行链接,成功完成链接
% sqlplus system/oracle@127.0.0.1:1521/xe SQL*Plus: Release 11.2.0.4.0 Production on Sat Mar 13 22:05:21 2021 Copyright (c) 1982, 2013, Oracle. All rights reserved. ERROR: ORA-28002: the password will expire within 7 days Connected to: Oracle Database 11g Express Edition Release 11.2.0.2.0 - 64bit Production SQL> quit