1 获取unixODBC和psqlodbc源码包

打开https://github.com/lurcher/unixODBC/tags,以下载unixODBC-2.3.7.tar.gz为例

打开https://www.postgresql.org/ftp/odbc/versions/src/,以下载psqlodbc-09.06.0500.tar.gz为例

将下载好的软件包放在 /home/postgres

2 编译安装unixODBC

执行如下命令安装

cd /home/postgres
tar -xf unixODBC-2.3.7.tar.gz
cd unixODBC-2.3.7
./configure --enable-gui=no --prefix=/home/postgres/odbc
make && make install
sed -i '$a export PATH=$PATH:/home/postgres/odbc/bin' /home/postgres/.bashrc
sed -i '$a export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/postgres/odbc/lib' /home/postgres/.bashrc
source /home/postgres/.bashrc

如果遇到报错:

config.status: error: cannot find input file: `Makefile.in'

执行如下代码:

yum -y install autoconf automake libtool libtool-ltdl-devel
aclocal
libtoolize --force
automake --add-missing
autoconf
autoheader
make clean

3 编译安装psqlODBC

cd /home/postgres
tar -xf psqlodbc-09.06.0500.tar.gz
cd psqlodbc-09.06.0500
./configure --prefix=/home/postgres/odbc
make && make install
sed -i '$a export ODBCSYSINI=/home/postgres/odbc/etc' /home/postgres/.bashrc
sed -i '$a export ODBCINI=/home/postgres/odbc/etc/odbc.ini' /home/postgres/.bashrc
source /home/postgres/.bashrc

4 配置数据源

  1. 配置ODBC驱动文件。在 /home/postgres/odbc/etc/odbcinst.ini 文件中追加以下内容。

    [PostgreSQL]									# 驱动器名称
    Driver64=/home/postgres/odbc/lib/psqlodbcw.so	# 驱动动态库的路径
    setup=/home/postgres/odbc/lib/psqlodbcw.so		# 驱动安装路径,与Driver64中动态库的路径一致
    
  2. 配置数据源文件。在 /home/postgres/odbc/etc/odbc.ini 文件中追加以下内容。

    [PSQLODBC]              # 数据源的名称
    Driver=PostgreSQL		# 驱动名,对应odbcinst.ini中的DriverName
    Servername=127.0.0.1 	# 数据库IP
    Database=postgres 		# 数据库名
    Username=postgres  		# 数据库用户名
    Password=postgres@123 	# 数据库用户密码
    Port=5432 				# 数据库侦听端口
    Sslmode=allow 			# 开启SSL模式
    
  3. 登录到数据库

    isql PSQLODBC
    
posted on 2024-01-23 21:26  jl1771  阅读(61)  评论(0编辑  收藏  举报