IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> 如何使用 datax 将 mysql 中的数据拉取到 hive ? -> 正文阅读

[大数据]如何使用 datax 将 mysql 中的数据拉取到 hive ?

需求

使用datax将mysql中的数据拉取到hive的ods层

步骤

首先在mysql中确定好需要拉取的表user_extend,
然后对应在hive中创建好空表,等待拉取

这里对应创建的hive表格如下

CREATE TABLE snbap_ods.ods_user_extend (
  user_id bigint   ,
  user_gender bigint   ,
  is_pregnant_woman tinyint  ,
  is_have_children tinyint  ,
  is_have_car tinyint  ,
  phone_brand string  ,
  phone_brand_level string  ,
  phone_cnt int   ,
  change_phone_cnt int   ,
  is_maja tinyint  ,
  majia_account_cnt int   ,
  loyal_model string  ,
  shopping_type_model string  ,
  weight int   ,
  height int   
)  
stored as textfile
location '/datax/mysql/snbap_ods/ods/ods_user_extend';

在datax的bin目录下创建json脚本 vi datax1.json

{
    "job": {
        "setting": {
             "speed": {
                "byte":1048576,
                "channel":"4"
            }
        },
        "content": [
            {
                "reader": {
                    "name": "mysqlreader",
                    "parameter": {
                        "username": "root",
                        "password": "root",
                        "connection": [
                            {
                                "querySql": [
                                    "select * from user_extend"
                                ],
                                "jdbcUrl": [
                                    "jdbc:mysql://localhost:3306/snbap_ods"
                                ]
                            }
                        ]
                    }
                },
                "writer": {
                    "name": "hdfswriter",
                    "parameter": {
                        "defaultFS":"hdfs://192.168.1.54:9000",
	        "fileType":"text",
	        "path":"/datax/mysql/snbap_ods/ods/ods_user_extend/",
	        "fileName":"user_extend",
                        "column": [
                        {"name":"user_id","type":"bigint"}
                        {"name":"user_gender","type":"bigint"}
                        {"name":"is_pregnant_woman","type":"tinyint"}
                        {"name":"is_have_children","type":"tinyint"}
                        {"name":"is_have_car","type":"tinyint"}
                        {"name":"phone_brand","type":"string"}
                        {"name":"phone_brand_level","type":"string"}
                        {"name":"phone_cnt","type":"int"}
                        {"name":"change_phone_cnt","type":"int"}
                        {"name":"is_maja","type":"tinyint"}
                        {"name":"majia_account_cnt","type":"int"}
                        {"name":"loyal_model","type":"string"}
                        {"name":"shopping_type_model","type":"string"}
                        {"name":"weight","type":"int"}
                        {"name":"height","type":"int"}
                        ],
                    "writeMode":"append",
         "fieldDelimiter":"\u0001",
	    "compress":"gzip"
                    }
                }
            }
        ]
    }
}

在datax的bin目录下运行以上json脚本

python /opt/install/datax/bin/datax.py /opt/install/datax/bin/datax1.json

运行成功的结果
在这里插入图片描述
最后在hive里查看表中数据 select * from ods_user_extend limit 10;

0: jdbc:hive2://localhost:10000> select * from ods_user_extend limit 10;
INFO  : Compiling command(queryId=root_20210709120808_33f5b7c6-df56-4474-8af9-329e0549b9f2): select * from ods_user_extend limit 10
INFO  : Semantic Analysis Completed
INFO  : Returning Hive schema: Schema(fieldSchemas:[FieldSchema(name:ods_user_extend.user_id, type:bigint, comment:null), FieldSchema(name:ods_user_extend.user_gender, type:bigint, comment:null), FieldSchema(name:ods_user_extend.is_pregnant_woman, type:tinyint, comment:null), FieldSchema(name:ods_user_extend.is_have_children, type:tinyint, comment:null), FieldSchema(name:ods_user_extend.is_have_car, type:tinyint, comment:null), FieldSchema(name:ods_user_extend.phone_brand, type:string, comment:null), FieldSchema(name:ods_user_extend.phone_brand_level, type:string, comment:null), FieldSchema(name:ods_user_extend.phone_cnt, type:int, comment:null), FieldSchema(name:ods_user_extend.change_phone_cnt, type:int, comment:null), FieldSchema(name:ods_user_extend.is_maja, type:tinyint, comment:null), FieldSchema(name:ods_user_extend.majia_account_cnt, type:int, comment:null), FieldSchema(name:ods_user_extend.loyal_model, type:string, comment:null), FieldSchema(name:ods_user_extend.shopping_type_model, type:string, comment:null), FieldSchema(name:ods_user_extend.weight, type:int, comment:null), FieldSchema(name:ods_user_extend.height, type:int, comment:null)], properties:null)
INFO  : Completed compiling command(queryId=root_20210709120808_33f5b7c6-df56-4474-8af9-329e0549b9f2); Time taken: 0.067 seconds
INFO  : Concurrency mode is disabled, not creating a lock manager
INFO  : Executing command(queryId=root_20210709120808_33f5b7c6-df56-4474-8af9-329e0549b9f2): select * from ods_user_extend limit 10
INFO  : Completed executing command(queryId=root_20210709120808_33f5b7c6-df56-4474-8af9-329e0549b9f2); Time taken: 0.0 seconds
INFO  : OK
+--------------------------+------------------------------+------------------------------------+-----------------------------------+------------------------------+------------------------------+------------------------------------+----------------------------+-----------------------------------+--------------------------+------------------------------------+------------------------------+--------------------------------------+-------------------------+-------------------------+--+
| ods_user_extend.user_id  | ods_user_extend.user_gender  | ods_user_extend.is_pregnant_woman  | ods_user_extend.is_have_children  | ods_user_extend.is_have_car  | ods_user_extend.phone_brand  | ods_user_extend.phone_brand_level  | ods_user_extend.phone_cnt  | ods_user_extend.change_phone_cnt  | ods_user_extend.is_maja  | ods_user_extend.majia_account_cnt  | ods_user_extend.loyal_model  | ods_user_extend.shopping_type_model  | ods_user_extend.weight  | ods_user_extend.height  |
+--------------------------+------------------------------+------------------------------------+-----------------------------------+------------------------------+------------------------------+------------------------------------+----------------------------+-----------------------------------+--------------------------+------------------------------------+------------------------------+--------------------------------------+-------------------------+-------------------------+--+
| 1                        | 1                            | 0                                  | 0                                 | 0                            | 华为                           | 一级                                 | 1                          | 3                                 | 0                        | 0                                  | 高度                           | 理智消费用户                               | 262                     | 178                     |
| 2                        | 1                            | 0                                  | 0                                 | 0                            | 华为                           | 一级                                 | 1                          | 3                                 | 0                        | 0                                  | 高度                           | 理智消费用户                               | 226                     | 209                     |
| 3                        | 1                            | 0                                  | 0                                 | 0                            | 华为                           | 一级                                 | 1                          | 3                                 | 0                        | 0                                  | 高度                           | 理智消费用户                               | 214                     | 133                     |
| 4                        | 1                            | 0                                  | 0                                 | 0                            | 华为                           | 一级                                 | 1                          | 3                                 | 0                        | 0                                  | 高度                           | 理智消费用户                               | 268                     | 212                     |
| 5                        | 1                            | 0                                  | 0                                 | 0                            | 华为                           | 一级                                 | 1                          | 3                                 | 0                        | 0                                  | 高度                           | 理智消费用户                               | 81                      | 158                     |
| 6                        | 0                            | 0                                  | 0                                 | 0                            | 华为                           | 一级                                 | 1                          | 3                                 | 0                        | 0                                  | 高度                           | 理智消费用户                               | 173                     | 212                     |
| 7                        | 0                            | 0                                  | 0                                 | 0                            | 华为                           | 一级                                 | 1                          | 3                                 | 0                        | 0                                  | 高度                           | 理智消费用户                               | 85                      | 141                     |
| 8                        | 1                            | 0                                  | 0                                 | 0                            | 华为                           | 一级                                 | 1                          | 3                                 | 0                        | 0                                  | 高度                           | 理智消费用户                               | 146                     | 199                     |
| 9                        | 0                            | 0                                  | 0                                 | 0                            | 华为                           | 一级                                 | 1                          | 3                                 | 0                        | 0                                  | 高度                           | 理智消费用户                               | 143                     | 314                     |
| 10                       | 0                            | 0                                  | 0                                 | 0                            | 华为                           | 一级                                 | 1                          | 3                                 | 0                        | 0                                  | 高度                           | 理智消费用户                               | 208                     | 209                     |
+--------------------------+------------------------------+------------------------------------+-----------------------------------+------------------------------+------------------------------+------------------------------------+----------------------------+-----------------------------------+--------------------------+------------------------------------+------------------------------+--------------------------------------+-------------------------+-------------------------+--+
10 rows selected (0.115 seconds)
0: jdbc:hive2://localhost:10000>

  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章           查看所有文章
加:2021-07-10 14:37:33  更:2021-07-10 14:39:38 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年5日历 -2024/5/6 18:46:51-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码