標籤:info oop name font schema 資料庫 test trend type
思路:讀取到一個資料庫裡所有的表名,然後通過sqoop迴圈匯入到hbase實現過程中發現 不會寫shell是個硬傷最後只能分兩步進行操作1.sel_tabs.sh
/usr/bin/mysql -hIp地址 -u使用者名稱 -p密碼 -D資料庫名<<EOFuse select table_name from information_schema.tables where table_schema=‘資料庫名‘ and table_type=‘base table‘;EOF
運行 bash sel_tabs.sh>tbsnam.dat
將結果寫入tbsname.dat
2.readdat.sh
#!/bin/sh cat tbsnam.dat |while read LINEdoecho $LINEif [ "$LINE" = "table_name" ]; thenecho "table_name test"elseecho $LINEstr="/opt/dtma/sqoop/bin/sqoop import --connect jdbc:mysql://Ip地址:連接埠號碼/資料庫名稱 --username ‘使用者名稱‘ --password ‘密碼‘ --table AA --hbase-table AA --column-family f1 --hbase-row-key id --hbase-create-table --m 1 --incremental append --check-column ‘id‘ --last-value 0" strend=${str//"AA"/$LINE}echo $strend $strend fidone
str是sqoop 增量匯入單個表的 語句
上面sql語句查詢結果 第一行出現 table_name,所以把table_name 剔除掉
最後運行
bash readdat.sh
mysql資料匯入到hbase