功能:shell获取多个oracle库mysql库所有的表
输入:数据库连接串配置文件
输出:每张表的属主,表名,表注释
shell获取mysql所有表的脚本如下:
示例:
#!/bin/bash
# 获取mysql所有表的主键
# get_mysql_tab.sh
# mysql连接串示例 jdbc:mysql://xxxx:4005/tpi|uat|uat$2022%
[ -e get_all_tab_mysql.log ] && rm get_all_tab_mysql.log
cat mysql_conn_str.conf |while read line
do
url=`echo $line|cut -d "|" -f 1`
user=`echo $line|cut -d "|" -f 2`
pwd=`echo $line|cut -d "|" -f 3`
my_sql="
SELECT table_schema,table_name,table_comment from information_schema.TABLES WHERE table_type='BASE TABLE' order by 1,2,3
"
/tpdata/sqoop_tool/sqoop-1.4.7.bin__hadoop-2.6.0/bin/sqoop eval \
--connect "${url}" \
--username "${user}" \
--password "${pwd}" \
--driver com.mysql.jdbc.Driver \
--query "${my_sql}" >> get_all_tab_mysql.log
done
shell获取oracle所有表如下:
#!/bin/bash
# 获取oracle所有表
# get_oracle_tab.sh
# oracle连接串示例 jdbc:oracle:thin:@xxxx:1521/tpi|uat|uat$2022%
[ -e get_all_tab_oracle.log ] && rm get_all_tab_oracle.log
cat oracle_conn_str.conf |while read line
do
url=`echo $line|cut -d "|" -f 1`
user=`echo $line|cut -d "|" -f 2`
pwd=`echo $line|cut -d "|" -f 3`
ora_sql="
SELECT owner,table_name,comments FROM all_tab_comments WHERE table_type='TABLE' order by 1,2,3
"
/tpdata/sqoop_tool/sqoop-1.4.7.bin__hadoop-2.6.0/bin/sqoop eval \
--connect "${url}" \
--username "${user}" \
--password "${pwd}" \
--query "${ora_sql}" >> get_all_tab_oracle.log
done