shell循環讀取資料庫
Ⅰ linux下編寫以個shell腳本,實現對oracle資料庫抽取指定條件的數據並且保存在一個文本文件中。
empno=100不存在的,改成有的數據了。
#!/bin/bash
result=$(sqlplus -s 'scott/tiger@dbname'<<EOF
spool test.txt
set pages 0
set feed off
set heading off;
set feedback off;
set verify off;
set linesize 1000;
SELECT * FROM scott.emp where empno=7369;
spool off
EOF
)
echo $result
~
~
~
~
~
~
~
~
~
"test.sh" 14L, 256C written
oracle@****:~> ./test.sh
7369 SMITH CLERK 7902 17-DEC-80 2240.06 20
oracle@****:~> more test.txt
7369 SMITH CLERK 7902 17-DEC-80 2240.06
20
Ⅱ shell腳本中執行db2資料庫操作,不知道哪裡錯了
方法一、適合所有格式的mysql資料庫,通過對資料庫導出導進寫個腳本定時執行:
1.導出整個資料庫 mysqlmp -u 用戶名 -p 資料庫名 > 導出的文件名 mysqlmp -u wcnc -p smgp_apps_wcnc > /存放路徑/wcnc.sql
2.導出一個表 mysqlmp -u 用戶名 -p 資料庫名 表名> 導出的文件名 mysqlmp -u wcnc -p smgp_apps_wcnc users> /存放路徑/wcnc_users.sql
3.導出一個資料庫結構 mysqlmp -u wcnc -p -d --add-drop-table smgp_apps_wcnc >/存放路徑/wcnc_db.sql
定義:
-d 沒有數據
--add-drop-table 在每個create語句之前增加一個drop table
4.導入資料庫 常用source 命令 進入mysql資料庫控制台:
如mysql -u root -p mysql>use 資料庫
方法二、針對mysql數據表格式為MyISAM的
假如數據文件在/var/lib/mysql
那麼直接寫個腳本
cp -r /var/lib/mysql /備份到的文件夾路徑
隔機備份用rsync增量,或定時完整備份。
Ⅲ aix k shell腳本while循環調用腳本只執行單次問題
可以把資料庫查詢的結果輸出到文件再對文件進行循環好一點
ssql="select a||'|'||b||'|'||c from table1 "
然後進入把結果輸出到一個文檔>>abc.unl
cat abc.unl |grep "|" |while read abc
do
a=`echo $abc|awk -F "|" '{print $1}'`
b=`echo $abc|awk -F "|" '{print $2}'`
ssh [email protected] /temp/test.ksh $a $b
done
rm abc.unl
Ⅳ LINUX下shell腳本如何執行 sql腳本 到DB2資料庫
1、在gedit中編寫.sh格式的文件,保存為a.sh。
Ⅳ 如何通過SHELL腳本取資料庫查詢內容
db2connectto[dbname]
db2"selectmin(a)fromb;">t.txt
db2terminate
date=`catt.txt|tail-2|head-1`
echo$date