×

数据库shell脚本编写

数据库shell脚本编写(如何写在Linux下写Shell脚本控制向mysql数据库里插数据啊~~~着急~~~)

admin admin 发表于2024-05-27 17:12:40 浏览20 评论0

抢沙发发表评论

本篇文章给大家谈谈数据库shell脚本编写,以及如何写在Linux下写Shell脚本控制向mysql数据库里插数据啊~~~着急~~~对应的知识点,文章可能有点长,但是希望大家可以阅读完,增长自己的知识,最重要的是希望对各位有所帮助,可以解决了您的问题,不要忘了收藏本站喔。

本文目录

如何写在Linux下写Shell脚本控制向mysql数据库里插数据啊~~~着急~~~

while(1){ $dbh = DBI-》connect ($connection_string, $userid, $username); $sth=$dbh-》prepare(insert into table(....) values(....)); $sth-》execute sleep (300); }

达梦数据库怎么写shell脚本,怎么通过shell脚本调用sql脚本

通过shell脚本调用sql脚本:1、shell脚本调用sql脚本 #首先sql文件 oracle@SZDB:~》 more dept.sql connect scott/tiger spool /tmp/dept.lst set linesize 100 pagesize 80 select * from dept; spool off; exit; #shell脚本文件,在shell脚本内调用sql脚本 oracle@SZDB:~》 more get_dept.sh #!/bin/bash # set environment variable if ; then . ~/.bashrc fi export ORACLE_SID=CNMMBO sqlplus -S /nolog @/users/oracle/dept.sql #注意此处执行sql脚本的方法 -S 表示以静默方式执行 exit #授予脚本执行权限 oracle@SZDB:~》 chmod 775 get_dept.sh --》执行shell脚本 oracle@SZDB:~》 ./get_dept.sh DEPTNO DNAME LOC ---------- -------------- ------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 2、shell脚本调用rman脚本 #首先RMAN脚本 oracle@SZDB:~》 more rman.rcv RUN { CONFIGURE RETENTION POLICY TO RECOVERY WINDOW OF 7 DAYS; CONFIGURE BACKUP OPTIMIZATION ON; CONFIGURE CONTROLFILE AUTOBACKUP ON; CONFIGURE CONTROLFILE AUTOBACKUP FORMAT FOR DEVICE TYPE DISK TO ’/users/oracle/bak/%d_%F’; ALLOCATE CHANNEL CH1 TYPE DISK MAXPIECESIZE=4G; ALLOCATE CHANNEL CH2 TYPE DISK MAXPIECESIZE=4G; SET LIMIT CHANNEL CH1 READRATE=10240; SET LIMIT CHANNEL CH1 KBYTES=4096000; SET LIMIT CHANNEL CH2 READRATE=10240; SET LIMIT CHANNEL CH2 KBYTES=4096000; CROSSCHECK ARCHIVELOG ALL; DELETE NOPROMPT EXPIRED ARCHIVELOG ALL; BACKUP DATABASE FORMAT ’/users/oracle/bak/%d_FULL__%U’; SQL ’ALTER SYSTEM ARCHIVE LOG CURRENT’; BACKUP ARCHIVELOG ALL FORMAT ’/users/oracle/bak/%d_LF_%U’ DELETE INPUT; DELETE NOPROMPT OBSOLETE; RELEASE CHANNEL CH1; RELEASE CHANNEL CH2; } #shell脚本文件,在shell脚本内调用rman脚本 oracle@SZDB:~》 more rman_bak.sh #!/bin/bash # set environment variable if ; then . ~/.bashrc fi export ORACLE_SID=CNMMBO $ORACLE_HOME/bin/rman target / cmdfile=/users/oracle/rman.rcv log=/users/oracle/bak/rman.log exit #授予脚本执行权限 oracle@SZDB:~》 chmod 775 rman_bak.sh #执行shell脚本

如何用shell脚本实现mysql数据库的操作

mysql -u root -p password -h localhost 《《!所要执行的sql语句!

写个shell脚本连接oracle数据库查询某表数据导出为txt文件,再发送到第三

1、简单的单列#!/bin/shsqlplus ’user001/12345678’《《 EOFset define offset hea offspool vip1.txt select username from ACCOUNT where LEVEL=7;spool offquit;EOFsed -i ’s/*//g’ ~/vip1.txtsed -i ’/^$/d’ ~/vip1.txtsed -i ’1d’ ~/vip1.txtsed -i ’$d’ ~/vip1.txtscp -P22 ~/vip1.txt root@172.16.1.2:/root2、复杂的多列#!/bin/shcid=$1;today=`date +%Y-%m-%d-%H.%M`ym=`date +%Y%m`ymd=`date -d -1days +%Y%m%d`last_ym=`date -d last-month +%Y%m`next_ym=`date -d next-month +%Y%m`file=chat_recorder_${cid}_20140707-11.xls if ;then echo "Usage: $0 company_id " exit 0;fisqlplus ’user002/12345678’ 《《 EOFset linesize 200set term off verify off feedback off pagesize 999set markup html on entmap ON spool on preformat offalter session set nls_date_format=’YYYY-MM-DD HH24:MI:SS’;spool ${file}select a.*,b.* from recorder_${ym} a,t_${ym} b where a.company_id=’$cid’ and a.create_time between TO_DATE(’2014-07-07 00:00:00’, ’YYYY-MM-DD HH24:MI:SS’) and TO_DATE(’2014-07-12 00:00:00’, ’YYYY-MM-DD HH24:MI:SS’) and a.chat_id=b.chat_id order by b.chat_id ;spool offquit;EOFsed -i ’/select/d’ $filezip -r ${file}.zip $filescp -P22 ${file}.zip root@172.16.1.5:/opt

用shell写个脚本完成对oracle数据库的增,删,改,查

sqlplus ${dbuser}/${dbpwd}@${dbname} 《《!truncate table table_name;exit;!

通过sqlplus连接数据库,然后写通过sql实现增,删,改,查

三个变量分别是 用户名、密码、数据库名称

以上就是我们为大家找到的有关“数据库shell脚本编写(如何写在Linux下写Shell脚本控制向mysql数据库里插数据啊~~~着急~~~)”的所有内容了,希望可以帮助到你。如果对我们网站的其他内容感兴趣请持续关注本站。