> 文章列表 > Pyspark_用户画像项目_1(数据通过Sqoop导入到Hive中)

Pyspark_用户画像项目_1(数据通过Sqoop导入到Hive中)

Pyspark_用户画像项目_1(数据通过Sqoop导入到Hive中)

Pyspark

注:大家觉得博客好的话,别忘了点赞收藏呀,本人每周都会更新关于人工智能和大数据相关的内容,内容多为原创,Python Java Scala SQL 代码,CV NLP 推荐系统等,Spark Flink Kafka Hbase Hive Flume等等~写的都是纯干货,各种顶会的论文解读,一起进步。
今天继续和大家分享一下Pyspark_用户画像项目_1
#博学谷IT学习技术支持


文章目录

  • Pyspark
  • 前言
  • 一、用户画像整体项目架构
  • 二、Mysql数据通过Sqoop导入到Hive中
    • 1.创建表
    • 2.导入数据
  • 总结

前言

博学谷Pyspark_用户画像项目_1
数据通过Sqoop导入到Hive中


一、用户画像整体项目架构

Pyspark_用户画像项目_1(数据通过Sqoop导入到Hive中)
其中先来关注离线部分

Pyspark_用户画像项目_1(数据通过Sqoop导入到Hive中)

二、Mysql数据通过Sqoop导入到Hive中

1.创建表

create-hive-table 创建一个Hive表, 读取mysql的表结构, 使用这个结构来创建Hive表

  • 用户表
/export/server/sqoop/bin/sqoop create-hive-table \\
--connect jdbc:mysql://up01:3306/tags_dat \\
--table tbl_users \\
--username root \\
--password 123456 \\
--hive-table tags_dat.tbl_users \\
--fields-terminated-by '\\t' \\
--lines-terminated-by '\\n'
  • 订单表
/export/server/sqoop/bin/sqoop create-hive-table \\
--connect jdbc:mysql://up01:3306/tags_dat \\
--table tbl_orders \\
--username root \\
--password 123456 \\
--hive-table tags_dat.tbl_orders \\
--fields-terminated-by '\\t' \\
--lines-terminated-by '\\n'
  • 商品表
/export/server/sqoop/bin/sqoop create-hive-table \\
--connect jdbc:mysql://up01:3306/tags_dat \\
--table tbl_goods \\
--username root \\
--password 123456 \\
--hive-table tags_dat.tbl_goods \\
--fields-terminated-by '\\t' \\
--lines-terminated-by '\\n''
  • 日志表
/export/server/sqoop/bin/sqoop create-hive-table \\
--connect jdbc:mysql://up01:3306/tags_dat \\
--table tbl_logs \\
--username root \\
--password 123456 \\
--hive-table tags_dat.tbl_logs \\
--fields-terminated-by '\\t' \\
--lines-terminated-by '\\n'

2.导入数据

direct 直接导出模式 会加快导出速度 使用关系型数据库自带的导出工具(mysql 会使用mysqldump命令)

  • 用户数据
/export/server/sqoop/bin/sqoop import \\
--connect jdbc:mysql://up01:3306/tags_dat \\
--username root \\
--password 123456 \\
--table tbl_users --direct --hive-overwrite --delete-target-dir --fields-terminated-by '\\t' --lines-terminated-by '\\n' --hive-table tags_dat.tbl_users --hive-import --num-mappers 1
  • 订单数据
/export/server/sqoop/bin/sqoop import \\
--connect jdbc:mysql://up01:3306/tags_dat \\
--username root \\
--password 123456 \\
--table tbl_orders --direct --hive-overwrite --delete-target-dir --fields-terminated-by '\\t' --lines-terminated-by '\\n' --hive-table tags_dat.tbl_orders --hive-import --num-mappers 10
  • 商品数据
/export/server/sqoop/bin/sqoop import \\
--connect jdbc:mysql://up01:3306/tags_dat \\
--username root \\
--password 123456 \\
--table tbl_goods --direct --hive-overwrite --delete-target-dir --fields-terminated-by '\\t' --lines-terminated-by '\\n' --hive-table tags_dat.tbl_goods --hive-import --num-mappers 5
  • 行为日志
/export/server/sqoop/bin/sqoop import \\
--connect jdbc:mysql://up01:3306/tags_dat \\
--username root \\
--password 123456 \\
--table tbl_logs --direct --hive-overwrite --delete-target-dir --fields-terminated-by '\\t' --lines-terminated-by '\\n' --hive-table tags_dat.tbl_logs --hive-import --num-mappers 20

总结

博学谷Pyspark_用户画像项目_1,数据通过Sqoop导入到Hive中