Golang连接Oracle 需要安装Oracle Full Client或Instant Client
#选择Instant Client for macOS (Intel x86)下载包如下:instantclient-basic-macos.x64-19.8.0.0.0dbru.zipinstantclient-sdk-macos.x64-19.8.0.0.0dbru.zipinstantclient-sqlplus-macos.x64-19.8.0.0.0dbru.zip#都解压到instantclient_19_8同一目录下unzip instantclient-basic-macos.x64-19.8.0.0.0dbru.zipunzip instantclient-sdk-macos.x64-19.8.0.0.0dbru.zipunzip instantclient-sqlplus-macos.x64-19.8.0.0.0dbru.zip#打印instantclient_19_8目录的路径pwd/Users/liang/software/oracle/instantclient_19_8
安装pkg-config
MacBook自带了pkg-config,这里不在安装
#打印pkg-config版本pkg-config --version
创建配置文件oci8.pc
vim /Users/liang/software/oracle/oci8.pc oci8.pc文件内容如下:
prefixdir=/Users/liang/software/oracle/instantclient_19_8libdir=${prefixdir}includedir=${prefixdir}/sdk/includeName: OCIDescription:Oracle database driverVersion:19.8Libs:-L${libdir}-lclntshCflags:-I${includedir}
配置环境变量
我用的是zsh,没有使用zsh的,可以添加到~/.bashrc文件 vim ~/.zshrc
添加如下环境变量# Oracle的OCI套件export LD_LIBRARY_PATH=/Users/liang/software/oracle/instantclient_19_8# oci8.pc文件所在路径export PKG_CONFIG_PATH=/Users/liang/software/oracle使配置生效source ~/.zshrc
运行Golang连接Oracle报错:
dyld:Librarynot loaded:@rpath/libclntsh.dylib.19.1Referencedfrom:/var/folders/_f/n3km_s7j6_9f8qzpkf9w395h0000gn/T/go-build114883360/b001/exe/oracleoci8Reason: image not found
添加软链接,解决报错
ln -s /Users/liang/software/oracle/instantclient_19_8/libclntsh.dylib.19.1/usr/local/lib/
注意:运行Golang时会提示 需要在系统偏好设置里--安全性和隐私 允许未知来源
<audio controls="controls" style="display: none;"></audio>