大數據入門到精通19--mysql 數據導入到hive數據中

一。正常按照數據庫和表導入mysql

\\前面介紹了經過底層文件得形式導入到hive的表中,或者直接導入到hdfs中,
\\如今介紹經過hive的database和table命令來從上層操做。
sqoop import --connect "jdbc:mysql://host03.xyy:3306/sakila" --username root --password root --table payment --where "payment_id<=8000" --hive-import --hive-database sakila --hive-table payment --delete-target-dir --num-mappers 2
\\追加導入數據
sqoop import --connect "jdbc:mysql://host03.xyy:3306/sakila" --username root --password root --table payment --where "payment_id >8000" --hive-import --hive-database sakila --hive-table payment --num-mappers 2
2、默認導入都是追加到表的方式,若是是指望覆蓋的方式
sqoop import --connect "jdbc:mysql://host03.xyy:3306/sakila" --username root --password root --table payment --where "payment_id >8000" --hive-import --hive-database sakila --hive-table payment hive-overwrite -- --num-mappers 2sql

3、建立表,並自動在hive裏面建立新表,並指定列類型轉換對應關係
sqoop import --connect "jdbc:mysql://host03.xyy:3306/sakila" --username root --password root --table payment --hive-import --hive-database sakila --hive-table payment2 --create-hive-table --map-column-hive payment_date=date,last_update=date --num-mappers 2數據庫

hive> desc payment;
OK
payment_id int
customer_id int
staff_id tinyint
rental_id int
amount double
payment_date string
last_update string
Time taken: 0.07 seconds, Fetched: 7 row(s)
hive> desc payment2;
OK
payment_id int
customer_id int
staff_id tinyint
rental_id int
amount double
payment_date date
last_update date
Time taken: 0.063 seconds, Fetched: 7 row(s)app

4、導入所有數據庫,
sqoop import-all-tables --connect "jdbc:mysql://host03.xyy:3306/sakila" --username root --password root --hive-import --hive-database sakila --num-mappers 2oop

相關文章
相關標籤/搜索