心有阳光 [openGauss](javascript:void(0);) 2023-08-08 18:00 发表于四川
收录于合集 #第六届 openGauss 技术文章征集初审合格文章 62 个
引言
openGauss 是一款开源的关系型数据库管理系统,它提供了强大的功能和性能,可以满足各种企业级应用的需求。与此同时,ODBC(Open Database Connectivity)是一个标准的数据库访问接口,它允许应用程序通过统一的方式与不同的数据库进行通信。本文将介绍如何在银河麒麟桌面操作系统进行 openGauss 的 ODBC 数据源配置。
环境准备
nwh@nwh-pc:~/桌面$ cat /etc/os-releaseNAME="Kylin"VERSION="银河麒麟桌面操作系统V10 (SP1)"VERSION_US="Kylin Linux Desktop V10 (SP1)"ID=kylinID_LIKE=debianPRETTY_NAME="Kylin V10 SP1"VERSION_ID="v10"HOME_URL="http://www.kylinos.cn/"SUPPORT_URL="http://www.kylinos.cn/support/technology.html"BUG_REPORT_URL="http://www.kylinos.cn/"PRIVACY_POLICY_URL="http://www.kylinos.cn"VERSION_CODENAME=kylinUBUNTU_CODENAME=kylinPROJECT_CODENAME=V10SP1KYLIN_RELEASE_ID="2303"
复制代码
设置应用保护
build-essential 包
nwh@nwh-pc:~/桌面$ sudo apt-get install -y build-essential正在读取软件包列表... 完成正在分析软件包的依赖关系树 正在读取状态信息... 完成 下列软件包是自动安装的并且现在不需要了: archdetect-deb dmeventd libaio1 libdebian-installer4 libdevmapper-event1.02.1 liblvm2cmd2.03 localechooser-data lvm2 user-setup使用'sudo apt autoremove'来卸载它(它们)。将会同时安装下列软件: cpp-10 g++ g++-10 g++-9 gcc-10 libasan6 libc-dev-bin libc6-dev libcrypt-dev libgcc-10-dev libstdc++-10-dev libstdc++-9-dev linux-libc-dev建议安装: gcc-10-locales g++-multilib g++-10-multilib gcc-10-doc g++-9-multilib gcc-9-doc gcc-10-multilib glibc-doc manpages-dev libstdc++-10-doc libstdc++-9-doc推荐安装: manpages manpages-dev下列【新】软件包将被安装: build-essential cpp-10 g++ g++-10 g++-9 gcc-10 libasan6 libc-dev-bin libc6-dev libcrypt-dev libgcc-10-dev libstdc++-10-dev libstdc++-9-dev linux-libc-dev升级了 0 个软件包,新安装了 14 个软件包,要卸载 0 个软件包,有 3 个软件包未被升级。需要下载 56.7 MB 的归档。解压缩后会消耗 224 MB 的额外空间。获取:1 http://archive.kylinos.cn/kylin/KYLIN-ALL 10.1-2303-hwe-updates/main amd64 libc-dev-bin amd64 2.31-0kylin9.2 [301 kB]......
复制代码
创建目录
nwh@nwh-pc:~$ mkdir -p odbc/etcnwh@nwh-pc:~$ ls公共的 视频 文档 音乐 bashrc.txt MPPODBC.txt openGauss-5.0.0-ODBC.tar.gz unixODBC-2.3.0.tar.gz unixODBC-2.3.7pre.tar.gz模板 图片 下载 桌面 GaussMPP.txt odbc unixODBC-2.3.0 unixODBC-2.3.5.tar.gznwh@nwh-pc:~$ cd odbc/nwh@nwh-pc:~/odbc$ lsetc
复制代码
安装 unixODBC
解压 unixODBC-2.3.0.tar.gz
nwh@nwh-pc:~$ tar -zxf unixODBC-2.3.0.tar.gz nwh@nwh-pc:~$ ll总用量 14676drwx------ 21 nwh nwh 4096 8月 4 00:03 ./drwxr-xr-x 3 root root 4096 8月 1 21:21 ../drwxr-xr-x 2 nwh nwh 4096 8月 1 21:24 公共的/drwxr-xr-x 2 nwh nwh 4096 8月 1 21:27 模板/drwxr-xr-x 2 nwh nwh 4096 8月 1 21:24 视频/drwxr-xr-x 2 nwh nwh 4096 8月 1 21:24 图片/drwxr-xr-x 2 nwh nwh 4096 8月 1 21:24 文档/drwxr-xr-x 2 nwh nwh 4096 8月 1 21:24 下载/drwxr-xr-x 2 nwh nwh 4096 8月 1 21:24 音乐/drwxr-xr-x 2 nwh nwh 4096 8月 1 21:27 桌面/-rw------- 1 nwh nwh 64 8月 1 22:02 .bash_history-rw-r--r-- 1 nwh nwh 220 4月 15 2020 .bash_logout-rw-r--r-- 1 nwh nwh 3854 4月 27 15:27 .bashrc-rw-rw-r-- 1 nwh nwh 184 8月 1 21:59 bashrc.txtdrwxrwxr-x 14 nwh nwh 4096 8月 3 23:42 .cache/drwx------ 14 nwh nwh 4096 8月 3 23:43 .config/drwx------ 3 nwh nwh 4096 8月 1 21:24 .dbus/-rw-r--r-- 1 nwh nwh 23 8月 1 21:24 .dmrc-rw-rw-r-- 1 nwh nwh 83 8月 1 21:59 GaussMPP.txtdrwx------ 3 nwh nwh 4096 8月 1 21:24 .gnupg/-rw-rw-r-- 1 nwh nwh 413 8月 3 23:42 .imwheelrcdrwxrwxr-x 2 nwh nwh 4096 8月 1 21:24 .kylin-os-manager-config/drwxrwxr-x 3 nwh nwh 4096 8月 1 21:24 .local/drwxr-xr-x 5 nwh nwh 4096 8月 3 23:44 .log/-rw-rw-r-- 1 nwh nwh 129 8月 1 21:59 MPPODBC.txt-rw-rw-r-- 1 nwh nwh 9455102 8月 1 22:00 openGauss-5.0.0-ODBC.tar.gzdrwx------ 2 nwh nwh 4096 8月 1 21:24 .presage/-rw-r--r-- 1 nwh nwh 807 4月 15 2020 .profiledrwxr-xr-x 2 nwh nwh 4096 8月 1 22:01 .qaxsafe/drwxrwxr-x 2 nwh nwh 4096 8月 1 21:24 .sogouinput/-rw-r--r-- 1 nwh nwh 0 8月 1 21:27 .sudo_as_admin_successful-rw-rw-r-- 1 nwh nwh 25 8月 1 21:33 .ukui-screensaver-default.confdrwxr-xr-x 19 nwh nwh 4096 4月 20 2010 unixODBC-2.3.0/-rw-rw-r-- 1 nwh nwh 1804749 8月 1 22:01 unixODBC-2.3.0.tar.gz-rw-rw-r-- 1 nwh nwh 1633390 8月 1 22:01 unixODBC-2.3.5.tar.gz-rw-rw-r-- 1 nwh nwh 1669682 8月 1 22:01 unixODBC-2.3.7pre.tar.gz-rw------- 1 nwh nwh 103 8月 3 23:41 .Xauthority-rw-r--r-- 1 nwh nwh 13 4月 27 15:38 .xsession-rw------- 1 nwh nwh 125000 8月 4 00:03 .xsession-errors-rw------- 1 nwh nwh 184349 8月 1 22:02 .xsession-errors.old
复制代码
修改 configure 文件
找到 LIB_VERSION,将它的值修改为"1:0:0",这样将编译出*.so.1 的动态库,与 psqlodbcw.so 的依赖关系相同。
编译 configure
nwh@nwh-pc:~/unixODBC-2.3.0$ ./configure --prefix=/home/nwh/odbc/checking for a BSD-compatible install... /usr/bin/install -cchecking whether build environment is sane... yeschecking for a thread-safe mkdir -p... /usr/bin/mkdir -pchecking for gawk... nochecking for mawk... mawkchecking whether make sets $(MAKE)... yeschecking for gawk... (cached) mawkchecking for bison... nochecking for byacc... nochecking for style of include used by make... GNUchecking for gcc... gccchecking for C compiler default output file name... a.outchecking whether the C compiler works... yeschecking whether we are cross compiling... no
......
复制代码
安装
nwh@nwh-pc:~/unixODBC-2.3.0$ make && make install
复制代码
替换客户端 openGauss 驱动程序
下载 ODBC 驱动包
下载 openEuler 20.03 LTS 环境下的 ODBC 驱动包
下载 openEuler 20.03 LTS 环境下的 ODBC 驱动包
下载 openEuler 20.03 LTS 环境下的 ODBC 驱动包
下载 ODBC 驱动包:https://opengauss.org/zh/download/
解压 ODBC 驱动包
nwh@nwh-pc:~$ mkdir -p installnwh@nwh-pc:~$ tar -zxf openGauss-5.0.0-ODBC.tar.gz -C install/nwh@nwh-pc:~$ ls公共的 图片 音乐 GaussMPP.txt odbc unixODBC-2.3.0.tar.gz模板 文档 桌面 install openGauss-5.0.0-ODBC.tar.gz unixODBC-2.3.5.tar.gz视频 下载 bashrc.txt MPPODBC.txt unixODBC-2.3.0 unixODBC-2.3.7pre.tar.gznwh@nwh-pc:~$ cd install/nwh@nwh-pc:~/install$ lslib odbc
复制代码
解压后会得到两个文件夹:lib 与 odbc;
在 odbc 文件夹中还会有一个 lib 文件夹。/odbc/lib 中会有“psqlodbca.la”,“psqlodbca.so”,“psqlodbcw.la”和“psqlodbcw.so”四个文件,将这四个文件拷贝到“/home/nwh/odbc/lib”目录下;
将 openGauss-5.0.0-ODBC.tar.gz 解压后 lib 目录中的库拷贝到“/home/nwh/odbc/lib”目录下。
nwh@nwh-pc:~/install$ pwd/home/nwh/installnwh@nwh-pc:~/install$ lslib odbcnwh@nwh-pc:~/install$ cd odbc/nwh@nwh-pc:~/install/odbc$ lslibnwh@nwh-pc:~/install/odbc$ cd lib/nwh@nwh-pc:~/install/odbc/lib$ cp * /home/nwh/odbc/lib/nwh@nwh-pc:~/install/odbc/lib$ cd ..nwh@nwh-pc:~/install/odbc$ cd ..nwh@nwh-pc:~/install$ cd lib/nwh@nwh-pc:~/install/lib$ cp * /home/nwh/odbc/lib/nwh@nwh-pc:~/install/lib$nwh@nwh-pc:~/odbc/lib$ pwd/home/nwh/odbc/libnwh@nwh-pc:~/odbc/lib$ lslibodbccr.la libodbccr.so.1 libodbcinst.la libodbcinst.so.1 libodbc.la libodbc.so.1 psqlodbca.la psqlodbcw.lalibodbccr.so libodbccr.so.1.0.0 libodbcinst.so libodbcinst.so.1.0.0 libodbc.so libodbc.so.1.0.0 psqlodbca.so psqlodbcw.sonwh@nwh-pc:~/odbc/lib$ lslibcom_err_gauss.so libgssrpc_gauss.so libkrb5support_gauss.so.0 libodbcinst.so.1 libpgport_tool.so libssl.solibcom_err_gauss.so.3 libgssrpc_gauss.so.4 libkrb5support_gauss.so.0.1 libodbcinst.so.1.0.0 libpgport_tool.so.1 libssl.so.1.1libcom_err_gauss.so.3.0 libgssrpc_gauss.so.4.2 libodbccr.la libodbcinst.so.2 libpq.a psqlodbca.lalibconfig.so libk5crypto_gauss.so libodbccr.so libodbcinst.so.2.0.0 libpq_ce.a psqlodbca.solibconfig.so.4 libk5crypto_gauss.so.3 libodbccr.so.1 libodbc.la libpq_ce.so psqlodbcw.lalibcrypto.so libk5crypto_gauss.so.3.1 libodbccr.so.1.0.0 libodbc.so libpq_ce.so.5 psqlodbcw.solibcrypto.so.1.1 libkrb5_gauss.so libodbccr.so.2 libodbc.so.1 libpq_ce.so.5.5libgssapi_krb5_gauss.so libkrb5_gauss.so.3 libodbccr.so.2.0.0 libodbc.so.1.0.0 libpq.solibgssapi_krb5_gauss.so.2 libkrb5_gauss.so.3.3 libodbcinst.la libodbc.so.2 libpq.so.5libgssapi_krb5_gauss.so.2.2 libkrb5support_gauss.so libodbcinst.so libodbc.so.2.0.0 libpq.so.5.5nwh@nwh-pc:~/odbc/lib$
复制代码
配置数据源
配置 ODBC 驱动文件
在“/home/nwh/odbc/etc/odbcinst.ini”文件中追加以下内容。
nwh@nwh-pc:~/odbc/etc$ vim odbcinst.ininwh@nwh-pc:~/odbc/etc$ vim odbcinst.ini[GaussMPP]Driver64=/home/nwh/odbc/lib/psqlodbcw.sosetup=/home/nwh/odbc/lib/psqlodbcw.so
复制代码
配置数据源文件
在“/home/nwh/odbc/etc/odbc.ini”文件中追加以下内容。
nwh@nwh-pc:~/odbc/etc$ vim odbc.ini[og]Driver=GaussMPP Servername=192.168.192.139 (数据库Server IP)Database=gaussdb (数据库名)Username=testuser (数据库用户名)Password=openGauss!666 (数据库用户密码)Port=15400 (数据库侦听端口)
复制代码
配置环境变量
nwh@nwh-pc:~$ vim ~/.bashrc
复制代码
在配置文件中追加以下内容。
export LD_LIBRARY_PATH=/home/nwh/odbc/lib:$LD_LIBRARY_PATHexport PATH=/home/nwh/odbc/bin:$PATHexport ODBCSYSINI=/home/nwh/odbc/etcexport ODBCINI=/home/nwh/odbc/etc/odbc.ini
复制代码
执行如下命令使设置生效。
nwh@nwh-pc:~$ source ~/.bashrc
复制代码
测试数据源配置
nwh@nwh-pc:~/odbc/bin$ isql -v og+---------------------------------------+| Connected! || || sql-statement || help [tablename] || quit || |+---------------------------------------+SQL>
复制代码
在弹出的对话框中点击“允许”按钮。
总结
ODBC 连接成功,就可以使用 ODBC 提供的函数来执行 SQL 查询和操作。ODBC 提供了一组标准的接口函数,可以执行各种数据库操作,如执行 SQL 查询、插入、更新和删除数据等。通过这些函数,可以在 openGauss 数据库中进行各种数据操作,满足应用程序需求。
通过使用 ODBC 接口,可以在 openGauss 中实现高效的数据访问和跨平台连接。ODBC 为开发人员提供了标准化的接口,并提供了一套丰富的函数来执行数据库操作。这种灵活性和可扩展性使得 openGauss 与 ODBC 的结合成为了开发企业级应用和在多平台上连接数据库的理想选择。
开始使用 openGauss 和 ODBC 吧,开启高效数据管理的新篇章!
非常感谢在本文相关形成过程中 openGauss 数据库官网 来杯拿铁(刘恒)老师给予的支持。
附录
记录在openEuler-22.03中安装openGauss_5.0.0企业版
在 VMware 17.0.2 虚拟机中安装 openEuler-22.03-LTS-SP2:https://www.modb.pro/db/1682365146923606016
Navicat连接openGauss_5.0.0 企业版数据库
评论