【Sqoop】Sqoop的使用(连接MySQL、Hive)

Sqoop的使用

使用sqoop前需要启动Hadoop,检查Hadoop的运行状态,我们这里使用的是伪分布式

[root@hr conf]# jps
1538 DataNode
2114 NodeManager
1689 SecondaryNameNode
1834 ResourceManager
1421 NameNode
2831 Jps

Sqoop连接MySQL需要MySQLjar包,吧jar包放置Sqooplib目录下

先测试Sqoop能否连接MySQL查看存在的数据库

sqoop list-databases --connect jdbc:mysql://192.168.0.161:3306/ --username root --password 123456

结果中的警告是因为没有配置Hbase,忽略即可

Warning: /home/sqoop/../hbase does not exist! HBase imports will fail.
Please set $HBASE_HOME to the root of your HBase installation.
Warning: /home/sqoop/../hcatalog does not exist! HCatalog jobs will fail.
Please set $HCAT_HOME to the root of your HCatalog installation.
Warning: /home/sqoop/../accumulo does not exist! Accumulo imports will fail.
Please set $ACCUMULO_HOME to the root of your Accumulo installation.
Warning: /home/sqoop/../zookeeper does not exist! Accumulo imports will fail.
Please set $ZOOKEEPER_HOME to the root of your Zookeeper installation.
22/03/16 04:27:14 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7
22/03/16 04:27:14 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.
22/03/16 04:27:14 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset.
Wed Mar 16 04:27:14 EDT 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.
information_schema
hive
mysql
performance_schema
sys

为了连接HIve我们需要将Hive组件lib目录下的hive-common-3.1.2.jar放到Sqoop组件的lib目录下

cp /home/hive/lib/hive-common-3.1.2.jar /home/sqoop/lib/

在MySQL中创建一个数据库和数据表,并随机插入一些数据

创建数据库和表

create database sample;
create table student(number char(9) primary key,name varchar(10));

添加数据

insert into student values('01','zhangsan');
insert into student values('02','lisi');
insert into student values('03','wangwu');

查看数据

mysql> select * from student;
+--------+----------+
| number | name     |
+--------+----------+
| 01     | zhangsan |
| 02     | lisi     |
| 03     | wangwu   |
+--------+----------+
3 rows in set (0.00 sec)

mysql> 

Hive中创建数据库和数据表

hive> create database sample; 
OK
Time taken: 0.566 seconds
hive> use sample;
OK
Time taken: 0.015 seconds
hive>  create table student(number STRING,name STRING) row format delimited fields terminated by ',';
Time taken: 0.499 seconds

MySQL 导出数据,导入Hive

sqoop参数说明

参数 意义
–connect MySQL 数据库连接 URL。
–username 和–password MySQL 数据库的用户名和密码。
–table 导出的数据表名。
–fields-terminated-by Hive 中字段分隔符。
–delete-target-dir 删除导出目的目录。
–num-mappers Hadoop 执行 Sqoop 导入导出启动的 map 任务数。
–hive-import --hive-database 导出到 Hive 的数据库名。
–hive-table 导出到 Hive 的表名。
sqoop import --connect jdbc:mysql://192.168.0.161:3306/sample --username root --password 123456 --table student --fields-terminated-by ',' --delete-target-dir --num-mappers 1 --hive-import --hive-database sample --hive-table student

运行日志

Warning: /home/sqoop/../hbase does not exist! HBase imports will fail.
Please set $HBASE_HOME to the root of your HBase installation.
Warning: /home/sqoop/../hcatalog does not exist! HCatalog jobs will fail.
Please set $HCAT_HOME to the root of your HCatalog installation.
Warning: /home/sqoop/../accumulo does not exist! Accumulo imports will fail.
Please set $ACCUMULO_HOME to the root of your Accumulo installation.
Warning: /home/sqoop/../zookeeper does not exist! Accumulo imports will fail.
Please set $ZOOKEEPER_HOME to the root of your Zookeeper installation.
22/03/16 05:03:24 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7
22/03/16 05:03:24 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.
22/03/16 05:03:24 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset.
22/03/16 05:03:24 INFO tool.CodeGenTool: Beginning code generation
Wed Mar 16 05:03:24 EDT 2022 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+,or set useSSL=true and provide truststore for server certificate verification.
22/03/16 05:03:25 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM `student` AS t LIMIT 1
22/03/16 05:03:25 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM `student` AS t LIMIT 1
22/03/16 05:03:25 INFO orm.CompilationManager: HADOOP_MAPRED_HOME is /home/hadoop
Note: /tmp/sqoop-root/compile/05aad1252e73aa2f62b414a7722fe98d/student.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
22/03/16 05:03:27 INFO orm.CompilationManager: Writing jar file: /tmp/sqoop-root/compile/05aad1252e73aa2f62b414a7722fe98d/student.jar
22/03/16 05:03:28 INFO tool.ImportTool: Destination directory student is not present,hence not deleting.
22/03/16 05:03:28 WARN manager.MySQLManager: It looks like you are importing from mysql.
22/03/16 05:03:28 WARN manager.MySQLManager: This transfer can be faster! Use the --direct
22/03/16 05:03:28 WARN manager.MySQLManager: option to exercise a MySQL-specific fast path.
22/03/16 05:03:28 INFO manager.MySQLManager: Setting zero DATETIME behavior to convertToNull (mysql)
22/03/16 05:03:28 INFO mapreduce.ImportJobBase: Beginning import of student
22/03/16 05:03:28 INFO Configuration.deprecation: mapred.jar is deprecated. Instead,use mapreduce.job.jar
22/03/16 05:03:28 INFO Configuration.deprecation: mapred.map.tasks is deprecated. Instead,use mapreduce.job.maps
22/03/16 05:03:28 INFO client.RMProxy: Connecting to ResourceManager at hr/192.168.0.161:8032
Wed Mar 16 05:03:30 EDT 2022 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+,or set useSSL=true and provide truststore for server certificate verification.
22/03/16 05:03:30 INFO db.DBInputFormat: Using read commited transaction isolation
22/03/16 05:03:30 INFO mapreduce.JobSubmitter: number of splits:1
22/03/16 05:03:30 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1647416961901_0001
22/03/16 05:03:31 INFO impl.YarnClientImpl: Submitted application application_1647416961901_0001
22/03/16 05:03:31 INFO mapreduce.Job: The url to track the job: http://hr:8088/proxy/application_1647416961901_0001/
22/03/16 05:03:31 INFO mapreduce.Job: Running job: job_1647416961901_0001
22/03/16 05:03:40 INFO mapreduce.Job: Job job_1647416961901_0001 running in uber mode : false
22/03/16 05:03:40 INFO mapreduce.Job:  map 0% reduce 0%
22/03/16 05:03:47 INFO mapreduce.Job:  map 100% reduce 0%
22/03/16 05:03:48 INFO mapreduce.Job: Job job_1647416961901_0001 completed successfully
22/03/16 05:03:48 INFO mapreduce.Job: Counters: 30
	File System Counters
		FILE: Number of bytes read=0
		FILE: Number of bytes written=133750
		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=30
		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)=3708
		Total time spent by all reduces in occupied slots (ms)=0
		Total time spent by all map tasks (ms)=3708
		Total vcore-seconds taken by all map tasks=3708
		Total megabyte-seconds taken by all map tasks=3796992
	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)=68
		CPU time spent (ms)=1020
		Physical memory (bytes) snapshot=110944256
		Virtual memory (bytes) snapshot=2081656832
		Total committed heap usage (bytes)=30474240
	File Input Format Counters 
		Bytes Read=0
	File Output Format Counters 
		Bytes Written=30
22/03/16 05:03:48 INFO mapreduce.ImportJobBase: Transferred 30 bytes in 20.1651 seconds (1.4877 bytes/sec)
22/03/16 05:03:48 INFO mapreduce.ImportJobBase: Retrieved 3 records.
22/03/16 05:03:48 INFO mapreduce.ImportJobBase: Publishing Hive/Hcat import job data to Listeners for table student
Wed Mar 16 05:03:48 EDT 2022 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+,or set useSSL=true and provide truststore for server certificate verification.
22/03/16 05:03:48 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM `student` AS t LIMIT 1
22/03/16 05:03:48 INFO hive.HiveImport: Loading uploaded data into Hive
22/03/16 05:03:48 INFO conf.HiveConf: Found configuration file file:/home/hive/conf/hive-site.xml
22/03/16 05:03:49 INFO hive.HiveImport: which: no hbase in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/home/jdk/bin:/home/jdk/bin:/home/sqoop/bin)
22/03/16 05:03:51 INFO hive.HiveImport: SLF4J: Class path contains multiple SLF4J bindings.
22/03/16 05:03:51 INFO hive.HiveImport: SLF4J: Found binding in [jar:file:/home/hive/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
22/03/16 05:03:51 INFO hive.HiveImport: SLF4J: Found binding in [jar:file:/home/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
22/03/16 05:03:51 INFO hive.HiveImport: SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
22/03/16 05:03:51 INFO hive.HiveImport: SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
22/03/16 05:03:52 INFO hive.HiveImport: Hive Session ID = 4b655330-3a4e-4ed4-b40f-599c1bff9652
22/03/16 05:03:52 INFO hive.HiveImport: 
22/03/16 05:03:52 INFO hive.HiveImport: Logging initialized using configuration in jar:file:/home/hive/lib/hive-common-3.1.2.jar!/hive-log4j2.properties Async: true
22/03/16 05:03:59 INFO hive.HiveImport: Hive Session ID = 57f33b0b-6433-4c3e-8277-4f020467d73b
22/03/16 05:04:00 INFO hive.HiveImport: OK
22/03/16 05:04:00 INFO hive.HiveImport: Time taken: 1.046 seconds
22/03/16 05:04:00 INFO hive.HiveImport: Loading data to table sample.student
22/03/16 05:04:01 INFO hive.HiveImport: OK
22/03/16 05:04:01 INFO hive.HiveImport: Time taken: 0.805 seconds
22/03/16 05:04:02 INFO hive.HiveImport: Hive import complete.
22/03/16 05:04:02 INFO hive.HiveImport: Export directory is contains the _SUCCESS file only,removing the directory.

去查看HIve上的表

hive> select * from sample.student;
OK
01	zhangsan
02	lisi
03	wangwu
Time taken: 2.154 seconds,Fetched: 3 row(s)

Hive 导出数据,导入到 MySQL

参数 意义
–connect MySQL 数据库连接 URL。
–username 和–password MySQL 数据库的用户名和密码。
–table 导出的数据表名。
–fields-terminated-by Hive 中字段分隔符。
–export-dir Hive 数据表在 HDFS 中的存储路径。
sqoop export --connect "jdbc:mysql://192.168.0.161:3306/sample?useUnicode=true&characterEncoding=utf-8" --username root --password 123456 --table student --input-fields-terminated-by ',' --export-dir /user/hive/warehouse/sample.db/student/*

Sqoop其他的命令
列出 MySQL 数据库中的所有数据库。

sqoop list-databases -connect jdbc:mysql://localhost:3306/ -username root -password 123456

连接MySQL并列出 sample数据库中的表。

sqoop list-tables -connect jdbc:mysql://localhost:3306/sample -username root -password 123456

将关系型数据的表结构复制到hive中,只是复制表的结构,表中的内容没有复制过去。

sqoop create-hive-table -connect jdbc:mysql://localhost:3306/sample -table student -username root -password 123456 -hive-table test

其中–table studentMySQL 中的数据库 sample中的表–hive-table testhive中新建的表名称。


从关系数据库导入文件到Hive中。

sqoop import --connect jdbc:mysql://localhost:3306/sample --username root --password 123456 --table student --delete-target-dir --num-mappers 1 --hive-import --hive-database default --hive-table test

Hive中的表数据导入到 MySQL 中,在进行导入之前,MySQL中的表hive_test表必须已经提前创建好。

sqoop export -connect jdbc:mysql://localhost:3306/sample -username root -password 123456 -table student --input-fields-terminatedby '\001' -export-dir /user/hive/warehouse/test

从数据库导出表的数据到 HDFS 上文件。

sqoop import -connect jdbc:mysql://localhost:3306/sample -username root -password 123456 -table student --num-mappers 1 -targetdir /user/test

从数据库增量导入表数据到 HDFS中。

sqoop import -connect jdbc:mysql://localhost:3306/sample -username root -password 123456 -table student --num-mappers 1 -targetdir /user/test -check-column number -incremental append -last-value 0

原文地址:https://blog.csdn.net/heiren_a

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


文章浏览阅读301次。你可以使用Thrift客户端来测试HBase Thrift服务。例如,在Python中,你可以使用。请确保你的HBase伪集群已正确配置并且Thrift服务已经启动。这将在你的伪集群中启动HBase Thrift服务。库或者直接使用Thrift接口。进入HBase的安装目录,找到。请根据需要进行相应的配置。这将停止Thrift服务。_hbase 单机 thrift 配置
文章浏览阅读565次。hive和hbase数据迁移_hive转hbase
文章浏览阅读707次。基于单机版安装HBase,前置条件为Hadoop安装完成,安装Hadoop可以参考链接,Hadoop单机安装。地址:https://dlcdn.apache.org/hbase/2.4.13/hbase-2.4.13-src.tar.gz2.解压缩文件3.进入到conf目录下4.修改配置文件 hbase-env.sh示例:示例:6.修改配置文件 hbase-site.xml示例:8.访问页面访问你所以在服务器的16010端口,查看页面以上就是单机版安装HBase的内容,后续_hbase 2.4.13下载
文章浏览阅读301次。linux集群搭建-HBase_linux中在/home目录下创建目录hbase
文章浏览阅读933次。中没有库的概念,说一个数据说的是哪一个名称空间下的那一张表下的哪一个行键的哪一个列族下面的哪一个列对应的是这个数据。注意:put数据需要指定往哪个命名空间的哪个表的哪个rowKey的哪个列族的哪个列中put数据,put的值是什么。注意:put数据需要指定往哪个命名空间的哪个表的哪个rowKey的哪个列族的哪个列中put数据,put的值是什么。注意:put数据需要指定往哪个命名空间的哪个表的哪个rowKey的哪个列族的哪个列中put数据,put的值是什么。操作Hbase系统DDL,对名称空间等进行操作。_hbase中报错undefined method for main:object
文章浏览阅读1k次,点赞16次,收藏21次。整理和梳理日常hbase的监控核心指标,作为经验沉淀_hbase 对应promethus指标名
文章浏览阅读1.5k次,点赞45次,收藏20次。今天把之前学习Hbase的入门基础知识笔记翻出来了,为了不忘记也是帮助身边的小伙伴,我把他又整理了下放了出来给大家,希望对HBASE一知半解的小伙伴,能够对Hbase有一个清晰的认识,好了废话不多说,进入正题。以上内容就是初的识HBase 入门知识,包含了hbase的由来,特性,物理存储,逻辑存储模型,以及优缺点,应用场景这些内容,相信后面在使用或更深入的研究Hbase打下了良好的基础,后面的更深入的学习内容,看计划安排在后面的文章中进行更新。
文章浏览阅读655次。HDFS,适合运行在通用硬件上的分布式文件系统,是一个高度容错性的系统,适合部署在廉价的机器上。Hbase,是一个分布式的、面向列的开源数据库,适合于非结构化数据存储。MapReduce,一种编程模型,方便编程人员在不会分布式并行编程的情况下,将自己的程序运行在分布式系统上。Chukwa,是一个开源的用于监控大型分布式系统的数据收集系统。_开源非结构化数据存储
文章浏览阅读1.9k次。mongodb和hbase的区别和应用场景_hbase和mongodb的区别
文章浏览阅读1.2k次。Hbase入门篇01---基本概念和部署教程_hbase教程
文章浏览阅读1.6k次,点赞19次,收藏25次。hbase相关内容
文章浏览阅读942次,点赞16次,收藏20次。在hbase1.x中transition是令广大大数据运维人员头疼的一个话题,因为,region 的状态转移涉及到了三个核心组件,分别为:hbase master,zookeeper和hbase 的regionserver,这三个组件中的某一个region的状态都是一致的情况下,这个region 才算是正常,状态转移过程及其复杂,hbase 集群很容易出现RIT。好消息是,hbase2.x中有个工具HBCK2,这个工具可不是简单的hbase1.x中hbck 的升级,变化有点大,详细变化请参考帮助文档(
文章浏览阅读1k次。在HBase中,Region分裂是一种自动的机制,用于在Region大小达到一定阈值时将其分裂成两个Region,以便更好地管理数据。HBase中的Region大小是可以配置的,通过设置HBase表的最小和最大Region大小来控制。需要注意的是,禁止Region分裂后,当表的大小达到一定阈值时,数据将不再分裂成新的Region,因此需要根据实际需求进行调整。需要注意的是,禁止Region分裂后,当表的大小达到一定阈值时,数据将不再分裂成新的Region,因此需要根据实际需求进行调整。_hbase region大小
文章浏览阅读737次。可以看出,HBase作为数据仓库的一种补充,可以用于存储和管理大量数据,以便快速地分析和查询。是一种基于数据库的形式,用于存储和管理大量数据,以便快速地分析和查询。例如,可以使用HBase存储一些用户行为数据,然后进行分析,以便更好地了解用户行为和需求。其次,需要配置HBase相关的环境变量,例如JAVA_HOME、HBASE_HOME等。HBase可以用于存储结构化和非结构化数据,包括文本、图像、视频等。例如,可以使用HBase存储一些传感器数据,然后进行实时分析和处理。一、HBase集群环境搭建。_用hbase 搭建数仓
文章浏览阅读1.9k次。Data。_springboot整合hbase
文章浏览阅读880次,点赞23次,收藏20次。etc/abrt下的两个文件,分别是:abrt-action-save-package-data.conf 和 abrt.conf,修改内容如下。我们后面排查的时候去查看/run/cloudera-scm-agent/process/2325-hbase-REGIONSERVER下是否有。发现有个hs_err_pid15967.log JVM生成的错误日志,那么把这个日志下载查看,返现日志这么写的。接下来就等下一次hbase的节点挂了之后查看转储文件,转储文件在/var/sqool/abrt下。_regionserver 退出 没有错误日志
文章浏览阅读1.7k次。以下命令都需要在Hbase Shell中运行:Hbase信息status:服务器状态version:版本表操作查看所有表:list表基本信息:describe "表名称"查看表是否存在:exists '表名称'创建表:create '表名称', '列族1', '列族2', '列族3'删除表:首先禁用表:disable '表名称'然后删除表:drop '表名称'修改表:表数据操作查看所有数据:scan "表名称"..._hbase sehll怎么看登录的是哪个hbase
文章浏览阅读885次,点赞18次,收藏21次。在HBase中执行查询操作通常使用HBase Shell或编程语言API(如Java或Python)来执行。使用编程语言API,您可以使用相应的HBase客户端库来执行查询操作。这是一个简单的Java代码示例,演示了如何使用HBase Java API进行单行查询。这些示例仅为基本查询操作,HBase Shell还提供其他高级查询功能,如按时间戳过滤,使用正则表达式进行查询等。请注意,这只是HBase查询的基本示例,您可以根据实际需求和HBase的数据模型进行更复杂的查询操作。
文章浏览阅读7.3k次,点赞7次,收藏28次。找到hbase的bin目录并进入,执行启动hbase hmaster命令。问题原因 hmaster挂了 ,需要重新启动hmaster才行。hbase shell输入命令出现如下问题。_keepererrorcode = nonode for /hbase/master
文章浏览阅读1.3k次。三次信息化浪潮。_大数据应用开发技术笔记