sqoop從mysql導(dǎo)入到hive例子 如何用sqoop將hive分區(qū)表信息導(dǎo)入到mysql命令?
如何用sqoop將hive分區(qū)表信息導(dǎo)入到mysql命令?問題分析:hive中主分區(qū)表其底層那是HDFS中的多個(gè)目錄下的單個(gè)文件,hive導(dǎo)出數(shù)據(jù)本質(zhì)是將HDFS中的文件導(dǎo)出hive中的分區(qū)表,只不過
如何用sqoop將hive分區(qū)表信息導(dǎo)入到mysql命令?
問題分析:
hive中主分區(qū)表其底層那是HDFS中的多個(gè)目錄下的單個(gè)文件,hive導(dǎo)出數(shù)據(jù)本質(zhì)是將HDFS中的文件導(dǎo)出
hive中的分區(qū)表,只不過分區(qū)字段(靜態(tài)硬盤分區(qū))不在文件中,因?yàn)樵趕qoop導(dǎo)入的時(shí)候,無法將分區(qū)字段進(jìn)行直接導(dǎo)入
思路:在hive中創(chuàng)建角色一個(gè)充當(dāng)表,將分區(qū)表剪切粘貼下來后分區(qū)字段裝換為特殊字段,然后再用sqoop將tmp表文件導(dǎo)入即基于需求
步湊::
文章目錄
1.創(chuàng)建家族目標(biāo)表(主分區(qū)表)
1.1一欄表結(jié)構(gòu)
2.導(dǎo)入數(shù)據(jù)
3.查詢表dept_partition
4.修改預(yù)備表tmp_dept_partition
5.查詢正式表
6.打開系統(tǒng)表結(jié)構(gòu)(這會兒硬盤分區(qū)表早就轉(zhuǎn)換的為非磁盤分區(qū)表了)
中建表dept_partition
8.在用sqoop再導(dǎo)入到MySQL
網(wǎng)站查詢驗(yàn)正有無成功了導(dǎo)出
1.創(chuàng)建家族目標(biāo)表(分區(qū)表)
hivegtCREATETABLE`dept_partition`(
`deptno`int,
`dname`string,
`loc`string)
PARTITIONEDbg(`month`string)rowformatdelimitedfieldsterminatedbyt.1查找表結(jié)構(gòu)
hivegtshowcreatetabledept_partition
1
1
------------------------------------------------------
|createtab_stmt|
------------------------------------------------------
|CREATETABLE`dept_partition`(|
|`deptno`int,|
|`dname`string,|
|`loc`string)|
|PARTITIONEDhe(|
|`month`string)str.lower2.導(dǎo)入數(shù)據(jù)
hivegtloaddatainpath/user/hive/hive_db/data/dept.txtintotabledept_partition
1
1
10tACCOUNTINGt1700tRESEARCHt1800tSALESt1900 tOPERATIONSt1700.可以查詢表dept_partition
hivegtselect*outsidedept_partition
1
1
---------------------------------------------------------------------------------------------
|dept_|dept_partition.dname|dept_partition.loc|dept_|
---------------------------------------------------------------------------------------------
|10|ACCOUNTING|1700|2019-10-19|
|20|RESEARCH|1800|2019-10-19|
|30|SALES|1900|2019-10-19|
|40|OPERATIONS|1700|2019-10-19|
|10|ACCOUNTING|1700|2019-10-20|
|20|RESEARCH|1800|2019-10-20|
|30|SALES|1900|2019-10-20|
|40|OPERATIONS|1700|2019-10-20|
---------------------------------------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
1
2
3
4
5
6
7
8
9
10
11
12
4.創(chuàng)建預(yù)備表tmp_dept_partition
hivegtcreatetabletmp_dept_partitionthoughselect*arounddept_partition
1
1
5.網(wǎng)上查詢充當(dāng)表
hivegtselect*returningtmp_dept_partition
1
1
-------------------------------------------------------------------------------------------------------------
|tmp_dept_|tmp_dept_partition.dname|tmp_dept_partition.loc|tmp_dept_|
-------------------------------------------------------------------------------------------------------------
|10|ACCOUNTING|1700|2019-10-19|
|20|RESEARCH|1800|2019-10-19|
|30|SALES|1900|2019-10-19|
|40|OPERATIONS|1700|2019-10-19|
|10|ACCOUNTING|1700|2019-10-20|
|20|RESEARCH|1800|2019-10-20|
|30|SALES|1900|2019-10-20|
|40|OPERATIONS|1700|2019-10-20|
-------------------------------------------------------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
1
2
3
4
5
6
7
8
9
10
11
12
6.查看表結(jié)構(gòu)(這會兒分區(qū)表早就轉(zhuǎn)換成為非分區(qū)表了)
hivegtshowcreatetabletmp_dept_partition
1
1
------------------------------------------------------
|createtab_stmt|
------------------------------------------------------
|CREATETABLE`tmp_dept_partition`(|
|`deptno`int,|
|`dname`string,|
|`loc`string,|
|`month`string)
1
2
3
4
5
6
7
8
1
2
3
4
5
6
7
8
中建表dept_partition
mysqlgtdroptableifexistsdept_partition
createtabledept_partition(
`deptno`int,
`dname`varchar(20),
`loc`varchar(20),
`month`varchar(50))
1
2
3
4
5
6
1
2
3
4
5
6
8.可以使用sqoop導(dǎo)出到MySQL
bin/sqoopexport
--connectjdbc:mysql://hadoop01:3306/partitionTb
--usernameroot
--password123456
--tabledept_partition
--num-mappers1
--export-dir/user/hive/warehouse/hive_db.db/tmp_dept_partition
--input-fields-terminated-by
Hadoop如何快速入門?
簡而言之下,我對hadoop的理解。
狹義上說:
Hadoop1.x版本是hdfsmapReduce
Hadoop2.x版本是hdfsyarnmapReduce
廣義上說:
haddop是一個(gè)生態(tài)。
建議您從1.x到2.x,先看架構(gòu),打聽一下1.x的架構(gòu)和缺點(diǎn)將近,2.x是怎么設(shè)計(jì)改進(jìn)的。現(xiàn)在會推出的3.x又有什么改進(jìn)呢?
生態(tài)圈,都有什么?每個(gè)模塊是干些什么的?工作中會有什么應(yīng)用場景?
以上是學(xué)習(xí)思路,祝成功,多謝了與我在線交流
Hadoop差不多要怎么學(xué)習(xí)這些內(nèi)容:
(1)去學(xué)習(xí)Hadoop的基本要求:
a、完全掌握J(rèn)avaSE
b、會在用maven工具
c、會使用IDE(eclipse、IDEA)
d、會建議使用Linux系統(tǒng)
(2)Hadoop詳細(xì)介紹和環(huán)境搭建
(3)HDFS底層工作原理、HDFS編程
(4)MapReduce原理、MapReduce實(shí)踐
(5)YARN原理及實(shí)踐
(6)Zookeeper原理及實(shí)踐
(7)Hbase、Hive、FlumeNG、Sqoop原理及實(shí)踐。
查找:Hadoop環(huán)境完全安裝可以設(shè)置
這個(gè)公眾號資源挺多的有編程、機(jī)電、手繪、攝影、英語等一系列視頻教材、天天更新。
公眾號:nnmiRS