大数据第九次作业

Sqoop安装与使用

使用sqoop进行将Hive词频统计的结果数据传输到Mysql中。

使用测试文件:

1. mysql准备接受数据的数据库与表

service mysql start #启动mysql服务
mysql -u root -p  #登陆shell界面
show databases;
create database if not exists wc;
use wc;
show tables;
create table if not exists `wc` (`word` varchar(100), `count` int) engine=InnoDB DEFAULT CHARSET =utf8;
desc wc;
show create table wc;

2. hive准备待传输的数据

stat-all.sh
jps
hive
show databases;
use hive;
show tables;
select * from wctext;
create table if not exists wc1  row format delimited fields terminated by '\t' as select word,count(1) as count from (select explode(split(line,' ')) as word from wctext) word group by word order by word ;
show create table wc1;
select * from wc1;
desc wc1;

3. sqoop进行数据传输

sqoop export --connect jdbc:mysql://127.0.0.1:3306/wc?useSSL=false --username root --password hadoop --table wc --export-dir /user/hive/warehouse/hive.db/wc1 --input-fields-terminated-by '\t'

4. mysql查看传输结果

use wc;
select * from wc;

使用电子书:

1. mysql准备接受数据的数据库与表

use wc;
show tables;
create table if not exists `wc3` (`word` varchar(100), `count` int) engine=InnoDB DEFAULT CHARSET =utf8;
desc wc3;
show create table wc3;

2. hive准备待传输的数据

上篇博客

3. sqoop进行数据传输

sqoop export --connect jdbc:mysql://127.0.0.1:3306/wc?useSSL=false --username root --password hadoop --table wc3 --export-dir /user/hive/warehouse/wctest --input-fields-terminated-by '\t'

4. mysql查看传输结果

use wc;
select * from wc2;
posted @ 2020-12-12 20:22  1After909  阅读(69)  评论(0编辑  收藏  举报