没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
Apache Sqoop系列文章
1、Apache Sqoop介绍及部署
2、sqoop导入(RMDB-mysql、sybase到HDFS-hive)
3、Sqoop导出(HDFS到RMDB-mysql)
4、Sqoop job作业
@TOC
本文是在前一篇的基础上介绍sqoop的使用,具体的部署环境请参考前一篇。
本文的前提是hadoop、mysql、hive环境都是好用的。
本文分为2个部分,即sqoop导入的简单介绍以及6种使用示例,包含sybase导入到hdfs。
一、Sqoop导入介绍
“导入工具”导入单个表从RDBMS到HDFS。表中的每一行被视为HDFS的记录。
所有记录都存储为文本文件的文本数据
1、语法结构
下面的语法用于将数据导入HDFS。
2、简单验证
二、使用示例
1、全量导入mysql表数据到HDFS
前提是对应的环境都是可用的,且是有测试数据的。
1)、导入
$ sqoop import (generic-args) (import-args)
----验证sqoop连接mysql 是否成功--列出该链接下的所有库
sqoop list-databases --connect jdbc:mysql://192.168.10.44:3306/test --username
root --password 88888
# 从MySQL数据库服务器中的person表导入HDFS
sqoop import --connect jdbc:mysql://192.168.10.44:3306/test --username root --
password 888888 \
--delete-target-dir \
--target-dir /test \
--table person \
--m 1
# 其中
# --target-dir可以用来指定导出数据存放至HDFS的目录;
# --delete-target-dir 删除target-dir目录,然后再重建
[root@server7 lib]# sqoop import --connect jdbc:mysql://192.168.10.44:3306/test
--username root --password 888888 \
> --delete-target-dir \
> --target-dir /test \
> --table person \
> --m 1
Warning: /opt/cloudera/parcels/CDH-6.2.1-
1.cdh6.2.1.p0.1425774/bin/../lib/sqoop/../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:/opt/cloudera/parcels/CDH-6.2.1-
1.cdh6.2.1.p0.1425774/jars/slf4j-log4j12-
1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/cloudera/parcels/CDH-6.2.1-
1.cdh6.2.1.p0.1425774/jars/log4j-slf4j-impl-
2.8.2.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]
22/11/08 15:12:19 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7-cdh6.2.1
22/11/08 15:12:19 WARN tool.BaseSqoopTool: Setting your password on the command-
line is insecure. Consider using -P instead.
22/11/08 15:12:19 INFO manager.MySQLManager: Preparing to use a MySQL streaming
resultset.
22/11/08 15:12:19 INFO tool.CodeGenTool: Beginning code generation
Tue Nov 08 15:12:19 CST 2022 WARN: Establishing SSL connection without server's
identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and
5.7.6+ requirements SSL connection must be established by default if explicit
option isn't set. For compliance with existing applications not using SSL the
verifyServerCertificate property is set to 'false'. You need either to
explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide
truststore for server certificate verification.
22/11/08 15:12:19 INFO manager.SqlManager: Executing SQL statement: SELECT t.*
FROM `person` AS t LIMIT 1
22/11/08 15:12:19 INFO manager.SqlManager: Executing SQL statement: SELECT t.*
FROM `person` AS t LIMIT 1
22/11/08 15:12:19 INFO orm.CompilationManager: HADOOP_MAPRED_HOME is
/opt/cloudera/parcels/CDH/lib/hadoop-mapreduce
22/11/08 15:12:22 ERROR orm.CompilationManager: Could not rename /tmp/sqoop-
root/compile/4f96760f8620e1c038672078f7a2ed66/person.java to
/opt/cloudera/parcels/CDH-6.2.1-
1.cdh6.2.1.p0.1425774/lib/sqoop/lib/./person.java. Error: Destination
'/opt/cloudera/parcels/CDH-6.2.1-
1.cdh6.2.1.p0.1425774/lib/sqoop/lib/./person.java' already exists
22/11/08 15:12:22 INFO orm.CompilationManager: Writing jar file: /tmp/sqoop-
root/compile/4f96760f8620e1c038672078f7a2ed66/person.jar
22/11/08 15:12:23 INFO tool.ImportTool: Destination directory /test deleted.
22/11/08 15:12:23 WARN manager.MySQLManager: It looks like you are importing
from mysql.
22/11/08 15:12:23 WARN manager.MySQLManager: This transfer can be faster! Use
the --direct
22/11/08 15:12:23 WARN manager.MySQLManager: option to exercise a MySQL-specific
fast path.
22/11/08 15:12:23 INFO manager.MySQLManager: Setting zero DATETIME behavior to
convertToNull (mysql)
22/11/08 15:12:23 INFO mapreduce.ImportJobBase: Beginning import of person
22/11/08 15:12:23 INFO Configuration.deprecation: mapred.jar is deprecated.
Instead, use mapreduce.job.jar
22/11/08 15:12:23 INFO Configuration.deprecation: mapred.map.tasks is
deprecated. Instead, use mapreduce.job.maps
22/11/08 15:12:23 INFO client.ConfiguredRMFailoverProxyProvider: Failing over to
rm46
22/11/08 15:12:23 INFO mapreduce.JobResourceUploader: Disabling Erasure Coding
for path: /user/root/.staging/job_1667806921128_0009
Tue Nov 08 15:12:31 CST 2022 WARN: Establishing SSL connection without server's
identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and
5.7.6+ requirements SSL connection must be established by default if explicit
option isn't set. For compliance with existing applications not using SSL the
verifyServerCertificate property is set to 'false'. You need either to
explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide
truststore for server certificate verification.
22/11/08 15:12:31 INFO db.DBInputFormat: Using read commited transaction
isolation
22/11/08 15:12:31 INFO mapreduce.JobSubmitter: number of splits:1
22/11/08 15:12:31 INFO Configuration.deprecation: yarn.resourcemanager.zk-
address is deprecated. Instead, use hadoop.zk.address
22/11/08 15:12:31 INFO Configuration.deprecation: yarn.resourcemanager.system-
metrics-publisher.enabled is deprecated. Instead, use yarn.system-metrics-
publisher.enabled
22/11/08 15:12:31 INFO mapreduce.JobSubmitter: Submitting tokens for job:
job_1667806921128_0009
22/11/08 15:12:31 INFO mapreduce.JobSubmitter: Executing with tokens: []
22/11/08 15:12:32 INFO conf.Configuration: resource-types.xml not found
22/11/08 15:12:32 INFO resource.ResourceUtils: Unable to find 'resource-
types.xml'.
22/11/08 15:12:32 INFO impl.YarnClientImpl: Submitted application
application_1667806921128_0009
22/11/08 15:12:32 INFO mapreduce.Job: The url to track the job:
http://server8:8088/proxy/application_1667806921128_0009/
22/11/08 15:12:32 INFO mapreduce.Job: Running job: job_1667806921128_0009
22/11/08 15:12:39 INFO mapreduce.Job: Job job_1667806921128_0009 running in uber
mode : false
22/11/08 15:12:39 INFO mapreduce.Job: map 0% reduce 0%
22/11/08 15:12:46 INFO mapreduce.Job: map 100% reduce 0%
22/11/08 15:12:46 INFO mapreduce.Job: Job job_1667806921128_0009 completed
successfully
22/11/08 15:12:47 INFO mapreduce.Job: Counters: 33
File System Counters
FILE: Number of bytes read=0
FILE: Number of bytes written=248904
FILE: Number of read operations=0
FILE: Number of large read operations=0
FILE: Number of write operations=0
HDFS: Number of bytes read=85
HDFS: Number of bytes written=248
HDFS: Number of read operations=6
剩余11页未读,继续阅读
资源评论
一瓢一瓢的饮alanchanchn
- 粉丝: 2827
- 资源: 69
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功