Linux配置golang-OCI8开发环境

OCI环境部署

  • 将下面3个文件解压并拷贝到/usr/local目录下
    instantclient-basic-linux.x64-12.2.0.1.0.zip
    instantclient-sdk-linux.x64-12.2.0.1.0.zip
    instantclient-sqlplus-linux.x64-12.2.0.1.0.zip
    下载地址
1
2
3
4
5
6
unzip -x instantclient-basic-linux.x64-12.2.0.1.0.zip
unzip -x instantclient-sdk-linux.x64-12.2.0.1.0.zip
unzip -x instantclient-sqlplus-linux.x64-12.2.0.1.0.zip
cp instantclient_12_2 /usr/local/instantclient
cd /usr/local/instantclient
ln -s libclntsh.so.12.1 libclntsh.so
  • 添加oci的配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
vim /usr/lib/pkgconfig/oci8.pc
# 内容如下
prefix=/usr/local/instantclient
exec_prefix=${prefix}
libdir=${prefix}
includedir=${prefix}/sdk/include
glib_genmarshal=glib-genmarshal
gobject_query=gobject-query
glib_mkenums=glib-mkenums
Name: oci8
Description: oci8 library
Libs: -L${libdir} -lclntsh
Cflags: -I${includedir}
Version: 12.2
# 再将环境变量写入profile
echo 'export PKG_CONFIG_PATH=/user/lib/pkgconfig' >>/etc/profile

测试oci安装成功
pkg-config --list-all | grep oci8

  • 配置客户端环境变量
1
2
3
4
5
vim ~/.bash_profile
# 内容如下
export ora_home=/usr/local/instantclient
export PATH=$PATH:$ora_home
export LD_LIBRARY_PATH=$ora_home

安装go-oci8包

go get github.com/mattn/go-oci8

0%