RDS下执行SQL小脚本

#!/bin/bash echo ‘ =============================== - 生产操作谨慎执行 - - - 提前预置SQL文件 - - =============================== ‘ read -p ‘请输入数据库用户:‘ mysql_user read -p ‘请输入数据库密码:‘ mysql_pass read -p ‘请输入数据库库名:‘ db_name read -p ‘请输入表名:‘ table_name read -p ‘请输入sql文件:‘ sql_name sql_path="/data1/sql" dump_path="/data1/mysql_dump" mysql_host="xxxx" mysql_port=3306 local_time=$(date +%Y%m%d-%k%M%S) /usr/bin/mysqldump -u${mysql_user} -p${mysql_pass} -h${mysql_host} -P${mysql_port} ${db_name} ${table_name} > ${dump_path}/${table_name}_${ local_time} if [ $? -ne 0 ];then echo "${db_name}.${table_name}备份失败" exit 255 else back_info=`/usr/bin/ls -shl ${dump_path}/${table_name}_${local_time}|awk ‘{print $1}‘` echo "备份成功,备份文件为:${table_name}_${local_time} 大小为:${back_info}" echo "请等待,正在导入SQL文件..." /usr/bin/mysql -u${mysql_user} -p${mysql_pass} -h${mysql_host} -P${mysql_port} ${db_name} < ${sql_path}/${sql_name} if [ $? -ne 0 ];then echo "${sql_name} 执行导入失败,若有报错请判断是否需要恢复" echo "${dump_path}/${table_name}_${local_time} 为本次脚本的备份文件" else echo "${sql_name} 导入成功,请联系测试人员验证" fi fi

RDS下执行SQL小脚本

上一篇:Oracle 11g CPU负载很高紧急处理【负载100%】


下一篇:各平台下oracle-instant-client安装部署