赞
踩
目录
启动Hadoop集群,MySQL
name,id,age(姓名,学号,年龄):
张三,2001,18
李四,2002,22
王五,2003,20
老六,2004,22
id,kcmc,xf(学号,课程名称,学分):
2001,大数据,2
2002,ETL,3
2003,python,1
2004,C语言,2
- create table hive_db03.stu
- (
- name string,
- id string,
- age string
- )
- row format delimited fields terminated by ',' stored as textfile;
- create table hive_db03.course
- (
- id string,
- kcmc string,
- xf string
- )
- row format delimited fields terminated by ',' stored as textfile;
查看创建的两个表:
show tables;
hdfs dfs -put stu.txt /user/hive/warehouse/hive_db03.db/stu
hdfs dfs -put course.txt /user/hive/warehouse/hive_db03.db/course
- create table hive_db03.stu_result
- (
- name string,
- kcmc string,
- xf string
- )
- row format delimited fields terminated by ',' stored as textfile;
insert into hive_db03.stu_result select m.name,n.kcmc,n.xf from hive_db03.stu m join hive_db03.course n on m.id=n.id;
- create table db3.stu_result
- (
- name varchar(50),
- kcmc varchar(50),
- xf varchar(20)
- );
(注:hive中的string对应MySQL中的varchar)
sqoop export -connect jdbc:mysql://192.168.43.21:3306/db3 -username sqoop03 -password 123456 -table stu_result -export-dir /user/hive/warehouse/hive_db03.db/stu_result -input-fields-terminated-by ','
[mysqld]
character-set-server=utf8
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
sqoop export -connect jdbc:mysql://192.168.43.21:3306/db3 -username sqoop03 -password 123456 -table stu_result -export-dir /user/hive/warehouse/hive_db03.db/stu_result -input-fields-terminated-by ','
将原数据库编码格式改变(与上面方法不同的是需要每个数据库修改编码)
- 删除原表:drop table xxx;
- 改变数据库编码:alter database db03 character set "utf8";
- 重新创表:create table xxx;
以上就是简单的sqoop导出过程!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。