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


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

\\前面介紹了通過底層文件得形式導入到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
二、默認導入都是追加到表的方式,如果是期望覆蓋的方式
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 2

三、創建表,並自動在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)

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM