如何使用 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
摘要由CSDN通过智能技术生成

需求

使用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
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
DataX 是阿里巴巴集团开源的一款数据同步工具,它支持多种数据源之间的同步,包括 HiveMySQL、Oracle 等常见关系型数据库以及 HDFS、FTP 等非关系型数据源。下面介绍如何使用 DataXHiveMySQL 的表互导。 首先需要在本地和远程服务器上安装好 DataX。然后创建一个名为 job.json 的配置文件,内容如下: ``` { "job": { "content": [ { "reader": { "name": "hdfswriter", "parameter": { "path": "/user/hive/warehouse/myhive.db/myhive_table", "defaultFS": "hdfs://localhost:9000", "fileType": "orc", "column": [ "col1", "col2", "col3" ] } }, "writer": { "name": "mysqlwriter", "parameter": { "url": "jdbc:mysql://localhost:3306/test", "username": "root", "password": "123456", "table": "mysql_table", "column": [ "col1", "col2", "col3" ] } } } ], "setting": { "speed": { "channel": "3" } } } } ``` 该配置文件定义了一个数据同步任务,将 Hive 的 myhive_table 表导入到 MySQL mysql_table 表。其,hdfswriter 和 mysqlwriter 分别表示数据源和目标源的类型,parameter 参数定义了数据源和目标源的详细信息。column 参数定义了需要同步的列。 执行以下命令启动 DataX 任务: ``` python datax.py job.json ``` 该命令会按照配置文件的定义开始数据同步任务。在数据量较大的情况下,可以通过修改 job.json 的 speed 参数来调整数据同步的速度,以避免对源和目标服务器的负载过大。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值