大数据入门到精通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

上一篇:设计模式之策略模式(Strategy Pattern)


下一篇:Linux 上安装 Couchbase服务