hbase結合hive和sqoop實現導資料到mysql,hbasesqoop
hive整合hbase表的兩點好處:
1.實現資料匯入到MYSQL。
2.實現hbase錶轉換為另外一張hbase表。
三個操作環節:
1.hbase關聯hive作為外部表格:
Sql代碼
- CREATE EXTERNAL TABLE hive_device_app(row_key string,genera_type string,install_type string,label string,meid string,model string,pkg_name string,specific_type string)
- STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
- WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf:genera_type,cf:install_type,cf:label,cf:meid,cf:model,cf:pkg_name,cf:specific_type")
- TBLPROPERTIES("hbase.table.name" = "tb_yl_device_app_info1");
2.hbase真正關聯hive,hive的插入更新等操作直接影響hbase中的資料
Sql代碼
- CREATE TABLE hbase_device_app(row_key string,genera_type string,install_type string,label string,meid string,model string,pkg_name string,specific_type string)
- STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
- WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf:genera_type,cf:install_type,cf:label,cf:meid,cf:model,cf:pkg_name,cf:specific_type")
- TBLPROPERTIES("hbase.table.name" = "tb_yl_device_app_info2");
3.建立一張hive表
Sql代碼
- CREATE TABLE hive_device_app_real(row_key string,genera_type string,install_type string,label string,meid string,model string,pkg_name string,specific_type string)
4.外部表格資料匯入hive實表
Sql代碼
- insert overwrite table hive_device_app_real select * from hive_device_app
5.sqoop匯出hive的資料到mysql
Sql代碼
- sqoop export --connect jdbc:mysql://Hadoop48/toplists -m 1 --table hive_device_app_real --export-dir /user/hive/warehouse/hive_device_app_real/000000_0 --input-null-string "\\\\N" --input-null-non-string "\\\\N" --input-fields-terminated-by "\\01" --input-lines-terminated-by "\\n"
6.habse(關聯hive)中一張錶轉到另外一張表當然可以利用hive的內建函數實現資料處理
Sql代碼
- insert overwrite table another_hive_hbase_related_table select * from hbase_device_app
匯出hbase中資料到mysql需要經過步驟:1345
hbase中一張表到另外一張表(中間可以利用hive內建函數做資料處理):226
sqoop匯入的資料 hbase可以直接用?還是需要在hbase裡見表格 然後再把匯入的資料插進去?
一條簡單的命令就可以
sqoop import --jar-file (你的jar包) --class-name (classname) --connect (mysql執行個體) --username (使用者名稱) --password (密碼) -table (表名) -hbase-table (hbase表名) -column-family (familyColumn) -hbase-row-key (hbase rowkey) --hbase-create-table
將mysql資料庫中資料通過sqoop匯入到hive中時報 javaioIOException: SQLException in nextKeyValue
將sql修改一下試試,相同效果的其他sql