Apache Sqoop HiveをMySQLにエクスポート

5666 ワード

1.宛先ライブラリMySQL関連パラメータ
1)接続構成
--connect jdbc:oracle:thin:@//10.xx.xx.xxx:1521/orcl 
--username bdas 
--password xxx

2)表の構成
--table xxx

2.hiveパラメータ構成
1)基本構成
--export-dir /user/hive/warehouse/dm.db/t_prc_video_join_count # hive   hdfs  
--columns xxx

2)更新挿入の上書き(オプション)
--update-key     
--update-mode allowinsert 

3.入力元区切り記号と空白列解析構成
--input-fields-terminated-by '\001' \
--input-lines-terminated-by '
'
\ --input-null-string "" \ --input-null-non-string "";

4.テスト users MySQL mktest users
まずMySQLでテーブルを作成します.
create table mktest.users(name varchar(20),host varchar(20));

まず、直接インポートしてみます.
sqoop export \
--connect jdbc:mysql://mycat01:3306/mktest \
--username root \
-password miku \
--table users \
--export-dir /user/hadoop/hive/warehouse/mktest.db/users  \
--m 3;

データを見てください.
mysql> select * from mktest.users;
+----------------+------+
| name           | host |
+----------------+------+
| rootmycat01   | NULL |
| root%         | NULL |
| rootlocalhost | NULL |
+----------------+------+

区切り記号の問題、設定してみてください(デフォルトフィールド区切り記号をエクスポートするのは\001です)
sqoop export \
--connect jdbc:mysql://mycat01:3306/mktest \
--username root \
-password miku \
--table users \
--export-dir /user/hadoop/hive/warehouse/mktest.db/users  \
--input-fields-terminated-by '\001' \
--m 3;


OK、今から結果を見てみましょう.
mysql> select * from mktest.users;
+------+-----------+
| name | host      |
+------+-----------+
| root | mycat01   |
| root | %         |
| root | localhost |
+------+-----------+


完全なsqoop shell:
sqoop export \
--connect jdbc:oracle:thin:@//10.xx.xx.xxx:1521/orcl \
--username xxx \
--password xx \
--table T_PRC_VIDEO_JOIN_COUNT \
--export-dir /user/hive/warehouse/dm.db/t_prc_video_join_count \
--columns operate_date,channel_no,channel_name,department_no,department_name,video_join_num,video_refuse_num,video_reject_num,video_pass_num,count_type,create_date,update_date \
--update-key operate_date,channel_no,department_no \
--update-mode allowinsert \
--input-fields-terminated-by '\001' \
--input-lines-terminated-by '
'
\ --input-null-string "" \ --input-null-non-string "";