我们要从MySQL当中导出数据到Greenplum当中,按照以下步骤就可以

1:将MySQL当中的表导出外部文件

以schema_name.table_name为例

select
product_id, number, name, english_name, purchase_name, system_name, bar_code, category_one, category_two, category_three,
parent_id, parent_number, brand_id, supplier_id, price, ad_word, give_integral, shelf_life, FROM_UNIXTIME(shelve_date), product_area, country,
sale_unit, specification, weight, length, width, height, storage_conditions, storage, model, refuse_notes, status, is_promote,
is_gift, is_book, is_outgoing, is_presale, is_fragile, is_have, is_cod, is_return, is_oos, is_seasonal, is_multicity, is_package, is_show, click,
favorite, min_purchase_unit, in_price, refer_in_price, mwaverage_price, is_unique_number, is_batch_number, qs_proportion, shelf_life_proportion, box_specification,
max_unsalable, advent_shelves, pro_warning, FROM_UNIXTIME(add_time), operator_id,FROM_UNIXTIME( audit_time), remark, price_type, new_tag, product_type, business_model, is_sell, return_policy,
package, inventory, merchant_number, modified_time ,now()
from schema_name.table_name INTO OUTFILE '/tmp/table_name.txt';

导的时候需要注意,一些字符的转换,对于这张表来说,主要就是在MySQL当中一些时间格式存储的为INT类型,我们需要进行转化后然后导出,而且在Greenplum当中建表的时候会多一个时间字段,我们这里默认导出现在时间。按照以上格式进行导出。

2:将文件拷贝到Greenplum服务器上,并且创建外部表

先将文件拷贝到外部表的目录下,这个比较简单,什么方法都可以,然后创建外部表:

create external  TABLE  schema_name.table_name_ext( product_id int,
number varchar(10),
name varchar(100),
english_name varchar(100),
purchase_name varchar(100),
system_name varchar(100),
bar_code varchar(255),
category_one int,
category_two int,
category_three int,
parent_id int,
parent_number int,
brand_id int,
supplier_id int,
price int,
ad_word varchar(100),
give_integral int,
shelf_life int,
shelve_date timestamp without time zone,
product_area int,
country int,
sale_unit varchar(20),
specification varchar(255),
weight decimal(10,2) ,
length int,
width int,
height int,
storage_conditions varchar(255),
storage smallint,
model varchar(20),
refuse_notes varchar(255),
status smallint,
is_promote smallint,
is_gift smallint,
is_book smallint,
is_outgoing smallint,
is_presale int,
is_fragile smallint,
is_have smallint,
is_cod smallint,
is_return smallint,
is_oos smallint,
is_seasonal smallint,
is_multicity smallint,
is_package smallint,
is_show smallint,
click int,
favorite int,
min_purchase_unit int,
in_price int,
refer_in_price int,
mwaverage_price int,
is_unique_number int,
is_batch_number int,
qs_proportion int,
shelf_life_proportion DOUBLE PRECISION,
box_specification varchar(50),
max_unsalable int,
advent_shelves int,
pro_warning int,
add_time timestamp without time zone,
operator_id int,
audit_time timestamp without time zone,
remark varchar(255),
price_type smallint,
new_tag int,
product_type int,
business_model smallint,
is_sell smallint,
return_policy smallint,
package varchar(200),
inventory varchar(200),
merchant_number int,
modified_time timestamp without time zone,
dw_modified_time timestamp without time zone
) location(
'gpfdist://172.16.16.34:9888/table_name.txt' )
FORMAT 'TEXT' SEGMENT REJECT LIMIT 1000000 rows ;
这里我们要指定'gpfdist://172.16.16.34:9888/table_name.txt',这个IP地址加上外部表就可以了,后面要把这个文件拷贝到 gpfdist 的目录当中,我们看下启动方式gpfdist -d /tmp -p 9888,也就是要把外部文件拷贝到/tmp目录下才可以。其他的注意列名对应就好
然后查询一下,一般情况列对上就不会有问题。
3:导入到Greenplum当中正式表

先创建一张正式表:

create table schema_name.table_name ( product_id int,
number varchar(10),
name varchar(100),
english_name varchar(100),
purchase_name varchar(100),
system_name varchar(100),
bar_code varchar(255),
category_one int,
category_two int,
category_three int,
parent_id int,
parent_number int,
brand_id int,
supplier_id int,
price int,
ad_word varchar(100),
give_integral int,
shelf_life int,
shelve_date timestamp without time zone,
product_area int,
country int,
sale_unit varchar(20),
specification varchar(255),
weight decimal(10,2) ,
length int,
width int,
height int,
storage_conditions varchar(255),
storage smallint,
model varchar(20),
refuse_notes varchar(255),
status smallint,
is_promote smallint,
is_gift smallint,
is_book smallint,
is_outgoing smallint,
is_presale int,
is_fragile smallint,
is_have smallint,
is_cod smallint,
is_return smallint,
is_oos smallint,
is_seasonal smallint,
is_multicity smallint,
is_package smallint,
is_show smallint,
click int,
favorite int,
min_purchase_unit int,
in_price int,
refer_in_price int,
mwaverage_price int,
is_unique_number int,
is_batch_number int,
qs_proportion int,
shelf_life_proportion DOUBLE PRECISION,
box_specification varchar(50),
max_unsalable int,
advent_shelves int,
pro_warning int,
add_time timestamp without time zone,
operator_id int,
audit_time timestamp without time zone,
remark varchar(255),
price_type smallint,
new_tag int,
product_type int,
business_model smallint,
is_sell smallint,
return_policy smallint,
package varchar(200),
inventory varchar(200),
merchant_number int,
modified_time timestamp without time zone,
dw_modified_time timestamp without time zone
) distributed by(product_id);

然后导入数据:

insert into schema_name.table_name
select * from schema_name.table_name_ext

这样就把外部表数据导出到了内部表,均匀分布在每个segment上。注意schema_name.table_name的结构要和schema_name.table_name_ext是一致的。

从MySQL向Greenplum集群中导入数据的更多相关文章

  1. 如何使用Hive&R从Hadoop集群中提取数据进行分析

    一个简单的例子! 环境:CentOS6.5 Hadoop集群.Hive.R.RHive,具体安装及调试方法见博客内文档. 1.分析题目 --有一个用户数据样本(表名huserinfo)10万数据左右: ...

  2. Kafka集群中 topic数据的分区 迁移到其他broker

    前言 kafka集群扩容后,新的broker上面不会数据进入这些节点,也就是说,这些节点是空闲的:它只有在创建新的topic时才会参与工作.除非将已有的partition迁移到新的服务器上面:所以需要 ...

  3. MySQL mysqlimport 从txt文件中导入数据到mysql数据库

    mysqlimport: 我说这个我们还是先从世界观方法论的高度来理解一下便有更加准确的把握.数据导入不外呼有两个部分 第一部分:目标对象--我们要把数据导给谁(mysqlimport 的目标对象自然 ...

  4. greenplum集群某台机器磁盘占用100%处理方式

    一.问题描述 使用gpfdist往集群中导入大量数据, 一段时间后连接退出,集群无法连接 二.问题定位 使用如下命令查看: gpstate -s mdw-:gpadmin-[INFO]:- Segme ...

  5. Mysql 高可用集群PXC

    PXC是percona公司的percona  xtraDB  cluster,简称PXC.它是基于Galera协议的高可用集群方案.可以实现多个节点间的数据同步复制以及读写,并且可保障数据库的服务高可 ...

  6. MySQL 8 InnoDB 集群管理

    使用 dba.checkInstanceConfiguration() 在添加实例到集群中前,使用该方法检查实例配置是否满足InnoDB 集群要求. 使用 dba.configureLocalInst ...

  7. ES:在线迁移集群索引,数据不丢失

    一.背景 生产环境由于某些原因需要跨机房迁移ES集群,或者同机房原有集群中所有节点全部更换,期间ES索引要求完整,客户端请求中断不超过五分钟. 二.应用场景 1.同机房不同集群之间数据迁移: 2.跨机 ...

  8. MySql集群FAQ----mysql主从配置与集群区别、集群中需要多少台计算机呢?为什么? 等

    抽取一部分显示在这里,如下, What's the difference in using Clustervs using replication? 在复制系统中,一个MySQL主服务器会更新一个或多 ...

  9. atlas+mysql主主集群实现读写分离

     atlas+mysql主主集群实现读写分离 前言: 目前线上系统数据库采用的是主主架构.其中一台主仅在故障时切换使用,(仅单台服务器对外提供服务,当一台出现问题,切换至另一台).该结构很难支撑较大并 ...

随机推荐

  1. ActiveMQ消息持久化到Mysql数据库

    1.把连接MySQL数据库的jar文件,放到ActiveMQ的lib目录下 2.修改ActiveMQ的conf目录下的activemq.xml文件,修改数据持久化的方式2.1 修改原来的kahadb的 ...

  2. mysql数据库修改字符编码问题

    遇到这种情况,现有项目的数据库已经建好,数据表也已经创建完成. 问题来的,数据库不能插入中文,调试时候发现中文数据从发送请求到最后请求处理完成这些步骤,中文还没有发生乱码. 只有在存储到数据库后查询数 ...

  3. nodejs zip压缩版安装与配置

    Node.js 1.下载 下载地址:https://nodejs.org/zh-cn/download/ 选择相应的版本下载 2.解压缩 将文件解压到要安装的位置,并新建两个目录 node-globa ...

  4. 使用Mac命令别名,提升工作效率

    为系统添加命令别名可以提高我们的工作效率,告别命令繁琐,庸长的的烦恼. Mac的~/.bash_profile文件提供了为系统添加命令别名的地方.所以我们要操作的也是这个文件. 下面是修改~/.bas ...

  5. CUBA 使用 Spring 查询接口

    原文链接:https://www.cuba-platform.com/blog/spring-query-interfaces-in-cuba 翻译:CUBA China CUBA-Platform ...

  6. Python urllib简单使用

    Python的urllib和urllib2模块都做与请求URL相关的操作. 它们最显著的差异为: urllib2可以接受一个Request对象,并以此可以来设置一个URL的headers,但是urll ...

  7. Message小结(二)

    当客户端调用一个WCF接口时,客户端将请求消息发送到服务端,服务端再返回回复消息.WCF内部实现了消息处理的所有细节,但是并不意味着一切不可更改.WCF也提供了一些方法让开发人员在消息发送前对消息进行 ...

  8. sqlserver数据导入导出问题

    sqlserver,如果用结果另存为,导出txt数据,然后在导入数据库,有时候会出问题,很难解决. 但是全选,右击,复制到自己创建的txt里面,在导入数据,就不会有问题的. 神奇,不知道为什么,但是能 ...

  9. THINK PHP 学习笔记20171115

    Part1:框架目录project 应用部署目录 ├─application 应用目录(可设置) │ ├─common 公共模块目录(可更改) │ ├─index 模块目录(可更改) │ │ ├─co ...

  10. SpringBoot(一)初遇

    环境: IDEA 2018.1.3 , jdk 1.8 , maven 3.3.9 零 第一次接触springboot, 如何学习比较困惑, 思前想后最后决定从文档来学习, 以下为学习中的参考资料: ...