从MySQL向Greenplum集群中导入数据
我们要从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集群中导入数据的更多相关文章
- 如何使用Hive&R从Hadoop集群中提取数据进行分析
一个简单的例子! 环境:CentOS6.5 Hadoop集群.Hive.R.RHive,具体安装及调试方法见博客内文档. 1.分析题目 --有一个用户数据样本(表名huserinfo)10万数据左右: ...
- Kafka集群中 topic数据的分区 迁移到其他broker
前言 kafka集群扩容后,新的broker上面不会数据进入这些节点,也就是说,这些节点是空闲的:它只有在创建新的topic时才会参与工作.除非将已有的partition迁移到新的服务器上面:所以需要 ...
- MySQL mysqlimport 从txt文件中导入数据到mysql数据库
mysqlimport: 我说这个我们还是先从世界观方法论的高度来理解一下便有更加准确的把握.数据导入不外呼有两个部分 第一部分:目标对象--我们要把数据导给谁(mysqlimport 的目标对象自然 ...
- greenplum集群某台机器磁盘占用100%处理方式
一.问题描述 使用gpfdist往集群中导入大量数据, 一段时间后连接退出,集群无法连接 二.问题定位 使用如下命令查看: gpstate -s mdw-:gpadmin-[INFO]:- Segme ...
- Mysql 高可用集群PXC
PXC是percona公司的percona xtraDB cluster,简称PXC.它是基于Galera协议的高可用集群方案.可以实现多个节点间的数据同步复制以及读写,并且可保障数据库的服务高可 ...
- MySQL 8 InnoDB 集群管理
使用 dba.checkInstanceConfiguration() 在添加实例到集群中前,使用该方法检查实例配置是否满足InnoDB 集群要求. 使用 dba.configureLocalInst ...
- ES:在线迁移集群索引,数据不丢失
一.背景 生产环境由于某些原因需要跨机房迁移ES集群,或者同机房原有集群中所有节点全部更换,期间ES索引要求完整,客户端请求中断不超过五分钟. 二.应用场景 1.同机房不同集群之间数据迁移: 2.跨机 ...
- MySql集群FAQ----mysql主从配置与集群区别、集群中需要多少台计算机呢?为什么? 等
抽取一部分显示在这里,如下, What's the difference in using Clustervs using replication? 在复制系统中,一个MySQL主服务器会更新一个或多 ...
- atlas+mysql主主集群实现读写分离
atlas+mysql主主集群实现读写分离 前言: 目前线上系统数据库采用的是主主架构.其中一台主仅在故障时切换使用,(仅单台服务器对外提供服务,当一台出现问题,切换至另一台).该结构很难支撑较大并 ...
随机推荐
- golang---interface结合reflect的泛型应用
大致思路:序列化未知json放入一个interface{}中再通过反射将其内容解析出来 str1:=`{ , , , , , , "type_key": "testnow ...
- Go语言学习笔记八: 数组
Go语言学习笔记八: 数组 数组地球人都知道.所以只说说Go语言的特殊(奇葩)写法. 我一直在想一个人参与了两种语言的设计,但是最后两种语言的语法差异这么大.这是自己否定自己么,为什么不与之前统一一下 ...
- 接口文档管理神器RAP2安装和部署
目录 一 RAP2 二 RAP2 安装需要的环境 2. 1 Node.js 安装: 2. 2 Mysql 5.7+ 安装 2 .3 Redis 安装见文章 2. 4 后端 rap2-delos 安装 ...
- Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in E:\\PHP\\wamp\\www\\lsr\\lsr.php on line 42
类似于这样的错误: 其实大多数的情况下,都是SQL语句书写错了,特别是这种情况: select * from order; 应该写成: select * from `order`;(那不是单引号,而是 ...
- 布局管理器之CardLayout(卡片布局管理器)
对于选项卡这个概念大家可能不会陌生,就是在一个窗口中可以切换显示多页不同的内容,但同一时间只能是其中的某一页可见的,这样的一个个的页面就是选项卡. CardLayout就是类似的这样一个布局管理器,它 ...
- SC Create 创建一个Windows系统服务 转
转自:http://www.360doc.com/content/13/0428/09/7555793_281451268.shtml sc create Serv-U binpath= &q ...
- 【Xmail】使用Xmail搭建局域网邮件服务器
下载地址: http://www.xmailserver.org/xmail-1.27.win32bin.zip,当前最新版本 1.27. 解压文件:xmail-1.27.win32bin.zip ...
- Golang 并发Groutine实例解读(一)
Go语言的并发和并行 不知道你有没有注意到一个现象,还是这段代码,如果我跑在两个goroutines里面的话: var quit chan int = make(chan int) func loop ...
- VS2013 项目项目安装和部署
版权声明:本文为博主原创文章,未经博主允许不得转载. 1.release 模式下生成项目 2.解决方案 右键 添加 新建项目 其他项目类型 安装和部署 3.操作前将待打包项目发布路径指向上述 ...
- c#基础学习(0724)之可变参数、ref和out
params可变参数,无论有几个参数,必须出现在参数列表的最后,可以为可变参数直接传递一个对应类型的数组 #region 可变参数 //1.如果方法有多个参数,可变参数可以作为最后一个参数 //2.可 ...