使用shell從DB2數據庫導出數據


使用shell腳本根據輸入的用戶名,數據庫名,密碼從DB2數據庫導出數據

(1)a.sh腳本如下

#!/usr/bin/bash
read -p "please input your DBNAME: " DBNAME
read -p "please input your username: " username
read -p "please input your password: " password
db2 connect to $DBNAME user $username using $password
db2 "EXPORT to /home/Practice/data/a.del of del select * from A"

(2)連接Linux,使用下面命令執行

su - db2inst1 -c "/home/Practice/a.sh"

上面這條代碼是關鍵,其中a.sh文件存儲在/home/Practice路徑下

[root@localhost Practice]# chmod +x a.sh
[root@localhost data]# su - db2inst1 -c "/home/Practice/a.sh"
please input your DBNAME: oliverdb
please input your username: db2inst1
please input your password: db2inst1

   Database Connection Information

 Database server        = DB2/LINUXX8664 10.5.5
 SQL authorization ID   = DB2INST1
 Local database alias   = OLIVERDB

SQL3104N  The Export utility is beginning to export data to file 
"/home/Practice/data/a.del".

SQL3105N  The Export utility has finished exporting "2" rows.


Number of rows exported: 2

到此處為止,數據已經從數據庫oiliverDB導出到了目錄/home/Practice/data下。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM