引言
openGauss是一款開源的關(guān)系型數(shù)據(jù)庫管理系統(tǒng)舷暮,它提供了強大的功能和性能,可以滿足各種企業(yè)級應(yīng)用的需求。與此同時薛夜,ODBC(Open Database Connectivity)是一個標(biāo)準(zhǔn)的數(shù)據(jù)庫訪問接口速梗,它允許應(yīng)用程序通過統(tǒng)一的方式與不同的數(shù)據(jù)庫進(jìn)行通信肮塞。本文將介紹如何在銀河麒麟桌面操作系統(tǒng)進(jìn)行openGauss的ODBC數(shù)據(jù)源配置襟齿。
環(huán)境準(zhǔn)備
VMware 17.0.2
openGauss_5.0.0
MobaXterm 22.1
服務(wù)器名稱:node0,IP地址:192.168.192.139
unixODBC-2.3.0
- 銀河麒麟桌面操作系統(tǒng)V10 (SP1)
NAME="Kylin"
VERSION="銀河麒麟桌面操作系統(tǒng)V10 (SP1)"
VERSION_US="Kylin Linux Desktop V10 (SP1)"
ID=kylin
ID_LIKE=debian
PRETTY_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=kylin
UBUNTU_CODENAME=kylin
PROJECT_CODENAME=V10SP1
KYLIN_RELEASE_ID="2303"
設(shè)置應(yīng)用保護(hù)
安全中心枕赵,設(shè)置應(yīng)用保護(hù)
build-essential 包
- 安裝 build-essential 包
正在讀取軟件包列表... 完成
正在分析軟件包的依賴關(guān)系樹
正在讀取狀態(tài)信息... 完成
下列軟件包是自動安裝的并且現(xiàn)在不需要了:
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]
......
創(chuàng)建目錄
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.gz
nwh@nwh-pc:~$ cd odbc/
nwh@nwh-pc:~/odbc$ ls
etc
安裝unixODBC
解壓 unixODBC-2.3.0.tar.gz
nwh@nwh-pc:~$ tar -zxf unixODBC-2.3.0.tar.gznwh@nwh-pc:~$ ll
總用量 14676
drwx------ 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.txt
drwxrwxr-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.txt
drwx------ 3 nwh nwh 4096 8月 1 21:24 .gnupg/
-rw-rw-r-- 1 nwh nwh 413 8月 3 23:42 .imwheelrc
drwxrwxr-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.gz
drwx------ 2 nwh nwh 4096 8月 1 21:24 .presage/
-rw-r--r-- 1 nwh nwh 807 4月 15 2020 .profile
drwxr-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.conf
drwxr-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的動態(tài)庫窄潭,與psqlodbcw.so的依賴關(guān)系相同。
編譯configure
nwh@nwh-pc:~/unixODBC-2.3.0$ ./configure --prefix=/home/nwh/odbc/checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking for gawk... (cached) mawk
checking for bison... no
checking for byacc... no
checking for style of include used by make... GNU
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
......
安裝
nwh@nwh-pc:~/unixODBC-2.3.0$ make && make install替換客戶端openGauss驅(qū)動程序
下載ODBC驅(qū)動包
下載openEuler 20.03 LTS環(huán)境下的ODBC驅(qū)動包
下載ODBC驅(qū)動包:https://opengauss.org/zh/download/
解壓ODBC驅(qū)動包
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.gz
nwh@nwh-pc:~$ cd install/
nwh@nwh-pc:~/install$ ls
lib 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/install
nwh@nwh-pc:~/install$ ls
lib odbc
nwh@nwh-pc:~/install$ cd odbc/
nwh@nwh-pc:~/install/odbc$ ls
lib
nwh@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/lib
nwh@nwh-pc:~/odbc/lib$ ls
libodbccr.la libodbccr.so.1 libodbcinst.la libodbcinst.so.1 libodbc.la libodbc.so.1 psqlodbca.la psqlodbcw.la
libodbccr.so libodbccr.so.1.0.0 libodbcinst.so libodbcinst.so.1.0.0 libodbc.so libodbc.so.1.0.0 psqlodbca.so psqlodbcw.so
nwh@nwh-pc:~/odbc/lib$ ls
libcom_err_gauss.so libgssrpc_gauss.so libkrb5support_gauss.so.0 libodbcinst.so.1 libpgport_tool.so libssl.so
libcom_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.1
libcom_err_gauss.so.3.0 libgssrpc_gauss.so.4.2 libodbccr.la libodbcinst.so.2 libpq.a psqlodbca.la
libconfig.so libk5crypto_gauss.so libodbccr.so libodbcinst.so.2.0.0 libpq_ce.a psqlodbca.so
libconfig.so.4 libk5crypto_gauss.so.3 libodbccr.so.1 libodbc.la libpq_ce.so psqlodbcw.la
libcrypto.so libk5crypto_gauss.so.3.1 libodbccr.so.1.0.0 libodbc.so libpq_ce.so.5 psqlodbcw.so
libcrypto.so.1.1 libkrb5_gauss.so libodbccr.so.2 libodbc.so.1 libpq_ce.so.5.5
libgssapi_krb5_gauss.so libkrb5_gauss.so.3 libodbccr.so.2.0.0 libodbc.so.1.0.0 libpq.so
libgssapi_krb5_gauss.so.2 libkrb5_gauss.so.3.3 libodbcinst.la libodbc.so.2 libpq.so.5
libgssapi_krb5_gauss.so.2.2 libkrb5support_gauss.so libodbcinst.so libodbc.so.2.0.0 libpq.so.5.5
nwh@nwh-pc:~/odbc/lib$
配置數(shù)據(jù)源
配置ODBC驅(qū)動文件
在“/home/nwh/odbc/etc/odbcinst.ini”文件中追加以下內(nèi)容油挥。nwh@nwh-pc:~/odbc/etc$ vim odbcinst.ininwh@nwh-pc:~/odbc/etc$ vim odbcinst.ini
[GaussMPP]
Driver64=/home/nwh/odbc/lib/psqlodbcw.so
setup=/home/nwh/odbc/lib/psqlodbcw.so
配置數(shù)據(jù)源文件
在“/home/nwh/odbc/etc/odbc.ini”文件中追加以下內(nèi)容。
nwh@nwh-pc:~/odbc/etc$ vim odbc.ini[og]
Driver=GaussMPP
Servername=192.168.192.139 (數(shù)據(jù)庫Server IP)
Database=gaussdb (數(shù)據(jù)庫名)
Username=testuser (數(shù)據(jù)庫用戶名)
Password=openGauss!666 (數(shù)據(jù)庫用戶密碼)
Port=15400 (數(shù)據(jù)庫偵聽端口)
配置環(huán)境變量
nwh@nwh-pc:~$ vim ~/.bashrc在配置文件中追加以下內(nèi)容款熬。
export LD_LIBRARY_PATH=/home/nwh/odbc/lib:$LD_LIBRARY_PATHexport PATH=/home/nwh/odbc/bin:$PATH
export ODBCSYSINI=/home/nwh/odbc/etc
export ODBCINI=/home/nwh/odbc/etc/odbc.ini
執(zhí)行如下命令使設(shè)置生效深寥。
nwh@nwh-pc:~$ source ~/.bashrc測試數(shù)據(jù)源配置
nwh@nwh-pc:~/odbc/bin$ isql -v og+---------------------------------------+
| Connected! |
| |
| sql-statement |
| help [tablename] |
| quit |
| |
+---------------------------------------+
SQL>
在彈出的對話框中點擊“允許”按鈕。
總結(jié)
ODBC連接成功贤牛,就可以使用ODBC提供的函數(shù)來執(zhí)行SQL查詢和操作惋鹅。ODBC提供了一組標(biāo)準(zhǔn)的接口函數(shù),可以執(zhí)行各種數(shù)據(jù)庫操作殉簸,如執(zhí)行SQL查詢闰集、插入、更新和刪除數(shù)據(jù)等般卑。通過這些函數(shù)武鲁,可以在openGauss數(shù)據(jù)庫中進(jìn)行各種數(shù)據(jù)操作,滿足應(yīng)用程序需求蝠检。
通過使用ODBC接口沐鼠,可以在openGauss中實現(xiàn)高效的數(shù)據(jù)訪問和跨平臺連接。ODBC為開發(fā)人員提供了標(biāo)準(zhǔn)化的接口,并提供了一套豐富的函數(shù)來執(zhí)行數(shù)據(jù)庫操作饲梭。這種靈活性和可擴展性使得openGauss與ODBC的結(jié)合成為了開發(fā)企業(yè)級應(yīng)用和在多平臺上連接數(shù)據(jù)庫的理想選擇乘盖。
開始使用openGauss和ODBC吧,開啟高效數(shù)據(jù)管理的新篇章排拷!
非常感謝在本文相關(guān)形成過程中 openGauss 數(shù)據(jù)庫官網(wǎng)來杯拿鐵(劉恒)老師給予的支持侧漓。
附錄
在VMware 17.0.2虛擬機中安裝openEuler-22.03-LTS-SP2:https://www.modb.pro/db/1682365146923606016
Navicat連接openGauss_5.0.0 企業(yè)版數(shù)據(jù)庫