热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

开发笔记:使用sqoop将mysql数据导入到hive(import)

篇首语:本文由编程笔记#小编为大家整理,主要介绍了使用sqoop将mysql数据导入到hive(import)相关的知识,希望对你有一定的参考价值。

篇首语:本文由编程笔记#小编为大家整理,主要介绍了使用 sqoop 将mysql数据导入到hive(import)相关的知识,希望对你有一定的参考价值。



Sqoop 将mysql 数据导入到hdfs(import)


1.创建mysql表


CREATE TABLE `sqoop_test` (
`id`
int(11) DEFAULT NULL,
`name` varchar(
255) DEFAULT NULL,
`age`
int(11) DEFAULT NULL
) ENGINE
=InnoDB DEFAULT CHARSET=latin1

插入数据

 


2.hive 建表


hive> create external table sqoop_test(id int,name string,age int)
> ROW FORMAT DELIMITED
> FIELDS TERMINATED BY \',\'
> STORED AS TEXTFILE
> location \'/user/hive/external/sqoop_test\';
OK
Time taken:
0.145 seconds

 


3.使用sqoop将mysql数据导入到hdfs


sqoop import --connect jdbc:mysql://localhost:3306/sqooptest --username root --password 123qwe --table sqoop_test --columns id,name,age --fields-terminated-by , --delete-target-dir --target-dir /user/hive/external/sqoop_test/ -m 1

--delete-target-dir:如果目标目录存在则删除。


EFdeMacBook-Pro:bin FengZhen$ sqoop import --connect jdbc:mysql://localhost:3306/sqooptest --username root --password 123qwe --table sqoop_test --columns id,name,age --fields-terminated-by , --delete-target-dir --target-dir /user/hive/external/sqoop_test/ -m 1
Warning: /Users/FengZhen/Desktop/Hadoop/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/../hcatalog does not exist! HCatalog jobs will fail.
Please
set $HCAT_HOME to the root of your HCatalog installation.
Warning:
/Users/FengZhen/Desktop/Hadoop/sqoop-1.4.6.bin__hadoop-2.0.4-alpha/../accumulo does not exist! Accumulo imports will fail.
Please
set $ACCUMULO_HOME to the root of your Accumulo installation.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding
in [jar:file:/Users/FengZhen/Desktop/Hadoop/hadoop-2.8.0/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding
in [jar:file:/Users/FengZhen/Desktop/Hadoop/hbase-1.3.0/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http:
//www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
17/09/13 11:12:19 INFO sqoop.Sqoop: Running Sqoop version: 1.4.6
17/09/13 11:12:19 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.
17/09/13 11:12:19 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset.
17/09/13 11:12:19 INFO tool.CodeGenTool: Beginning code generation
17/09/13 11:12:19 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM `sqoop_test` AS t LIMIT 1
17/09/13 11:12:19 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM `sqoop_test` AS t LIMIT 1
17/09/13 11:12:19 INFO orm.CompilationManager: HADOOP_MAPRED_HOME is /Users/FengZhen/Desktop/Hadoop/hadoop-2.8.0
17/09/13 11:12:21 INFO orm.CompilationManager: Writing jar file: /tmp/sqoop-FengZhen/compile/1a0c4154ffefb21d4af720813dd0b3fc/sqoop_test.jar
17/09/13 11:12:21 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
17/09/13 11:12:22 INFO tool.ImportTool: Destination directory /user/hive/external/sqoop_test deleted.
17/09/13 11:12:22 WARN manager.MySQLManager: It looks like you are importing from mysql.
17/09/13 11:12:22 WARN manager.MySQLManager: This transfer can be faster! Use the --direct
17/09/13 11:12:22 WARN manager.MySQLManager: option to exercise a MySQL-specific fast path.
17/09/13 11:12:22 INFO manager.MySQLManager: Setting zero DATETIME behavior to convertToNull (mysql)
17/09/13 11:12:22 INFO mapreduce.ImportJobBase: Beginning import of sqoop_test
17/09/13 11:12:22 INFO Configuration.deprecation: mapred.job.tracker is deprecated. Instead, use mapreduce.jobtracker.address
17/09/13 11:12:22 INFO Configuration.deprecation: mapred.jar is deprecated. Instead, use mapreduce.job.jar
17/09/13 11:12:22 INFO Configuration.deprecation: mapred.map.tasks is deprecated. Instead, use mapreduce.job.maps
17/09/13 11:12:22 INFO client.RMProxy: Connecting to ResourceManager at localhost/127.0.0.1:8032
17/09/13 11:12:24 INFO db.DBInputFormat: Using read commited transaction isolation
17/09/13 11:12:24 INFO mapreduce.JobSubmitter: number of splits:1
17/09/13 11:12:24 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1505268150495_0008
17/09/13 11:12:25 INFO impl.YarnClientImpl: Submitted application application_1505268150495_0008
17/09/13 11:12:25 INFO mapreduce.Job: The url to track the job: http://192.168.1.64:8088/proxy/application_1505268150495_0008/
17/09/13 11:12:25 INFO mapreduce.Job: Running job: job_1505268150495_0008
17/09/13 11:12:35 INFO mapreduce.Job: Job job_1505268150495_0008 running in uber mode : false
17/09/13 11:12:35 INFO mapreduce.Job: map 0% reduce 0%
17/09/13 11:12:41 INFO mapreduce.Job: map 100% reduce 0%
17/09/13 11:12:41 INFO mapreduce.Job: Job job_1505268150495_0008 completed successfully
17/09/13 11:12:41 INFO mapreduce.Job: Counters: 30
File System Counters
FILE: Number of bytes read
=0
FILE: Number of bytes written
=156817
FILE: Number of read operations
=0
FILE: Number of large read operations
=0
FILE: Number of write operations
=0
HDFS: Number of bytes read
=87
HDFS: Number of bytes written
=26
HDFS: Number of read operations
=4
HDFS: Number of large read operations
=0
HDFS: Number of write operations
=2
Job Counters
Launched map tasks
=1
Other local map tasks
=1
Total time spent by all maps
in occupied slots (ms)=3817
Total time spent by all reduces
in occupied slots (ms)=0
Total time spent by all map tasks (ms)
=3817
Total vcore
-milliseconds taken by all map tasks=3817
Total megabyte
-milliseconds taken by all map tasks=3908608
Map
-Reduce Framework
Map input records
=3
Map output records
=3
Input split bytes
=87
Spilled Records
=0
Failed Shuffles
=0
Merged Map outputs
=0
GC time elapsed (ms)
=33
CPU time spent (ms)
=0
Physical memory (bytes) snapshot
=0
Virtual memory (bytes) snapshot
=0
Total committed heap usage (bytes)
=154140672
File Input Format Counters
Bytes Read
=0
File Output Format Counters
Bytes Written
=26
17/09/13 11:12:41 INFO mapreduce.ImportJobBase: Transferred 26 bytes in 18.6372 seconds (1.3951 bytes/sec)
17/09/13 11:12:41 INFO mapreduce.ImportJobBase: Retrieved 3 records.

 

可在hdfs看到传入的数据


EFdeMacBook-Pro:jarfile FengZhen$ hadoop fs -ls /user/hive/external/sqoop_test
Found
2 items
-rw-r--r-- 1 FengZhen supergroup 0 2017-09-13 11:12 /user/hive/external/sqoop_test/_SUCCESS
-rw-r--r-- 1 FengZhen supergroup 26 2017-09-13 11:12 /user/hive/external/sqoop_test/part-m-00000

 

可在hive中查看数据。


hive> select * from sqoop_test;
OK
1 fz 13
3 dx 18
2 test 13
Time taken:
1.756 seconds, Fetched: 3 row(s)

使用sqoop将hive数据导出到mysql(export)



推荐阅读
  • 本文探讨了如何使用Scrapy框架构建高效的数据采集系统,以及如何通过异步处理技术提升数据存储的效率。同时,文章还介绍了针对不同网站采用的不同采集策略。 ... [详细]
  • Hadoop MapReduce 实战案例:手机流量使用统计分析
    本文通过一个具体的Hadoop MapReduce案例,详细介绍了如何利用MapReduce框架来统计和分析手机用户的流量使用情况,包括上行和下行流量的计算以及总流量的汇总。 ... [详细]
  • 使用Java计算两个日期之间的月份数
    本文详细介绍了利用Java编程语言计算两个指定日期之间月份数的方法。文章通过实例代码讲解了如何使用Joda-Time库来简化日期处理过程,旨在为开发者提供一个高效且易于理解的解决方案。 ... [详细]
  • iOS如何实现手势
    这篇文章主要为大家展示了“iOS如何实现手势”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“iOS ... [详细]
  • 本文介绍了如何使用Flume从Linux文件系统收集日志并存储到HDFS,然后通过MapReduce清洗数据,使用Hive进行数据分析,并最终通过Sqoop将结果导出到MySQL数据库。 ... [详细]
  • 本文详细介绍了Hive中用于处理日期和时间的各种函数,包括UNIX时间戳与日期之间的转换、日期提取以及日期计算等,帮助读者更好地理解和使用这些函数。 ... [详细]
  • 本文介绍了一种在 Android 开发中动态修改 strings.xml 文件中字符串值的有效方法。通过使用占位符,开发者可以在运行时根据需要填充具体的值,从而提高应用的灵活性和可维护性。 ... [详细]
  • 本文详细介绍了如何使用Linux下的mysqlshow命令来查询MySQL数据库的相关信息,包括数据库、表以及字段的详情。通过本文的学习,读者可以掌握mysqlshow命令的基本语法及其常用选项。 ... [详细]
  • HDU 2537 键盘输入处理
    题目描述了一个名叫Pirates的男孩想要开发一款键盘输入软件,遇到了大小写字母判断的问题。本文提供了该问题的解决方案及实现方法。 ... [详细]
  • Java连接MySQL数据库的方法及测试示例
    本文详细介绍了如何安装MySQL数据库,并通过Java编程语言实现与MySQL数据库的连接,包括环境搭建、数据库创建以及简单的查询操作。 ... [详细]
  • 本文详细介绍了如何通过JDBC连接Hive进行数据操作,包括Hive服务的启动、相关依赖的配置以及具体代码示例,适合对Hive和JDBC有一定了解的开发者阅读。 ... [详细]
  • C/C++ 应用程序的安装与卸载解决方案
    本文介绍了如何使用Inno Setup来创建C/C++应用程序的安装程序,包括自动检测并安装所需的运行库,确保应用能够顺利安装和卸载。 ... [详细]
  • binlog2sql,你该知道的数据恢复工具
    binlog2sql,你该知道的数据恢复工具 ... [详细]
  • 深入解析 C++ 中的 String 和 Vector
    本文详细介绍了 C++ 编程语言中 String 和 Vector 的使用方法及特性,旨在帮助开发者更好地理解和应用这两个重要的容器。 ... [详细]
  • 从0到1搭建大数据平台
    从0到1搭建大数据平台 ... [详细]
author-avatar
寻找冄己靉
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有