如何创建icloud邮箱箱如何不用真实姓名

随笔 - 271
阅读排行榜
评论排行榜
60天内阅读排行知识库 : Sqoop1、Sqoop2功能差异及使用示例
Created by
肖松林, last modified on
功能差异及使用示例
用于所有主要
解决办法:
使用已在以下数据库上执行测试的通用
Microsoft SQL Server
PostgreSQL
此连接器应在任何其它符合
要求的数据库上运行。但是,性能可能无法与
中的专用连接器相比
解决办法:
按照此两步方法操作。
解决办法:
按照此两步方法操作。
相同的解决方法操作
架构非常简单,其整合了
map-reduce
任务来传输数据,从而提供并发特性和容错。
和关系数据库进行交互。理论上支持
都可以使用
进行数据交互
yum install sqoop sqoop-metastore -y
安装完之后需要下载
mysql-connector-java-5.1.32-bin.jar
如果使用默认的
会出现以下错误
# sqoop help
Warning: /usr/lib/sqoop/../accumulo does not exist! Accumulo imports will fail.
Please set $ACCUMULO_HOME to the root of your Accumulo installation.
15/08/27 15:58:24 INFO sqoop.Sqoop: Running Sqoop version: 1.4.5-cdh5.4.3
usage: sqoop COMMAND [ARGS]
Available commands:
Generate code to interact with database records
create-hive-table
Import a table definition into Hive
Evaluate a SQL statement and display the results
Export an HDFS directory to a database table
List available commands
Import a table from a database to HDFS
import-all-tables
Import tables from a database to HDFS
import-mainframe
Import datasets from a mainframe server to HDFS
Work with saved jobs
list-databases
List available databases on a server
list-tables
List available tables in a database
Merge results of incremental imports
Run a standalone Sqoop metastore
Display version information
See 'sqoop help COMMAND' for information on a specific command.
# /usr/lib/sqoop/bin/sqoop-list-databases --connect jdbc:mysql://20.12.20.12:3306/ --username root
Warning: /usr/lib/sqoop/bin/../../accumulo does not exist! Accumulo imports will fail.
Please set $ACCUMULO_HOME to the root of your Accumulo installation.
15/08/27 16:06:35 INFO sqoop.Sqoop: Running Sqoop version: 1.4.5-cdh5.4.3
15/08/27 16:06:35 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset.
information_schema
库,则连接没问题
sqoop import
命令可以从关系数据库导入数据到
sqoop import --connect jdbc:mysql://20.12.20.12:3306/sqoop --username root
--table test -m 1 --target-dir /user/hive/result
mysql jdbc url
如果重复执行,会提示目录已经存在,可以手动删除
如果不指定
--target-dir
,导入到用户家目录下的
你还可以指定其他的参数:
将数据追加到
中已经存在的
中已经存在的
中。使用该参数,
将把数据先导入到一个临时目录中,然后重新给文件命
名到一个正式的目录中,以避免和该目录中已存在的文件重名。
--as-avrodatafile
将数据导入到一个
数据文件中
--as-sequencefile
将数据导入到一个
--as-textfile
将数据导入到一个普通文本文件中,生成该文本文件后,可以在
语句查询出结果。
--boundary-query &statement&
边界查询,也就是在导入前先通过
查询得到一个结果集,然后导入的数据就是该结果集内的数据,格式如:
--boundary-query 'select id,no from t where id = 3'
,表示导入的数据为
的记录,或者
select min(&split-by&), max(&split-by&) from &table name&
,注意查询的字段中不能有数据类型为字符串的字段,否则会报错
--columns&col,col&
指定要导入的字段值,格式如:
--columns id,username
直接导入模式,使用的是关系数据库自带的导入导出工具。官网上是说这样导入会更快
--direct-split-size
在使用上面
直接导入的基础上,对导入的流按字节数分块,特别是使用直连模式从
PostgreSQL
导入数据的时候,可以将一个到达设定大小的文件分为几个独立的文件。
--inline-lob-limit
设定大对象数据类型的最大值
-m,--num-mappers
来并行导入数据,默认是
个,最好不要将数字设置为高于集群的节点数
从查询结果中导入数据,该参数使用时必须指定–
target-dir
hive-table
,在查询语句中一定要有
条件中需要包含
\$CONDITIONS
--query 'select * from t where \$CONDITIONS ' --target-dir /tmp/t
hive-table t
--split-by &column&
表的列名,用来切分工作单元,一般后面跟主键
--target-dir &dir&
--delete-target-dir
删除目标目录
--warehouse-dir &dir&
--target-dir
不能同时使用,指定数据导入的存放目录,适用于
导入,不适合导入
从关系数据库导入数据时的查询条件,示例:
--where "id = 2"
-z,--compress
默认情况下数据是没被压缩的,通过该参数可以使用
压缩算法对数据进行压缩,适用于
SequenceFile, text
--compression-codec
压缩编码,默认是
--table &table-name&
关系数据库表名,数据从该表中获取
sqoop import --connect jdbc:mysql://20.12.20.11:3306/hive --username root --password 123456 --table TBLS --columns "tbl_id,create_time" --where "tbl_id & 1" --target-dir /user/hive/result
# hadoop fs -cat /user/hive/result/part-m-00000
# hadoop fs -cat /user/root/test.txt
1,aaaaaa,bbbb
2,cccccc,dddd
3,eeeeee,ffff
执行下面的命令会将
中的数据导入到
#sqoop export --connect jdbc:mysql://20.12.20.12:3306/sqoop --username root --table yonyou --export-dir '/user/root/test.txt' --fields-terminated-by ','
mysql& select *
+------+--------+------+
+------+--------+------+
1 | aaaaaa | bbbb |
2 | cccccc | dddd |
3 | eeeeee | ffff |
+------+--------+------+
3 rows in set (0.00 sec)
生成与关系数据库表的表结构对应的
#sqoop create-hive-table --connect jdbc:mysql://20.12.20.12:3306/sqoop
--username root --table yonyou
--hive-home &dir&
的安装目录,可以通过该参数覆盖掉默认的
--hive-overwrite
表中已经存在的数据
--create-hive-table
,如果目标表已经存在了,那么创建任务会失败
--hive-table
后面接要创建的
指定关系数据库表名
执行下面的命令会将
中的数据导入到
中,然后创建一个
表,最后再将
上的文件移动到
表的目录下面。
#sqoop import --connect jdbc:mysql://20.12.20.11:3306/hive --username root --password 123456 --table TBLS --fields-terminated-by "\t" --lines-terminated-by "\n" --hive-import --hive-overwrite --create-hive-table --hive-table dw_srclog.TBLS --delete-target-dir
的表名前面指定数据库名称
--create-hive-table
创建表,如果表已经存在则会执行失败
接下来可以查看
中的数据:
# hive -e 'select * from dw_srclog.tbls'
Logging initialized using configuration in file:/etc/hive/conf.dist/hive-log4j.properties
MANAGED_TABLE
test_yonyou
MANAGED_TABLE
MANAGED_TABLE
Time taken: 3.02 seconds, Fetched: 3 row(s)
直接查看文件内容:
# hadoop fs -cat /user/hive/warehouse/dw_srclog.db/tbls/part-m-0000*
MANAGED_TABLE
test_yonyou
MANAGED_TABLE
MANAGED_TABLE
在架构上,
sqoop server
(具体服务器为
实现了集中的管理。其访问方式也变得多样化了,其可以通过
控制台方式进行访问。另外,其在安全性能方面也有一定的改善,在
中我们经常用脚本的方式将
中的数据导入到
中,或者反过来将
数据导入到
中,其中在脚本里边都要显示指定
数据库的用户名和密码的,安全性做的不是太完善。在
中,如果是通过
方式访问的话,会有一个交互过程界面,你输入的密码信息不被看到。
被分布为两个单独的软件包;一个客户端软件包
(sqoop2-client)
和一个服务器软件包
(sqoop2-server)
。在集群中的一个节点上安装服务器包;因为
Sqoop2 Server
客户端,所以此节点必须已安装和配置
在将充当客户端的每个节点上安装客户端包。
客户端将始终连接至
Sqoop2 Server
,以执行任何操作,因此,
无需安装在客户端节点上。
这里客户端和服务器安装在同一节点上
# yum install sqoop2-server sqoop2-client
包不能安装在与
包相同的机器上。但是,您可以通过在不同节点上安装
集群中使用两个版本。
服务端的启动
sqoop2-server start
使用以下命令,以交互式模式启动客户端:
sqoop:000& help
For information about Sqoop, visit: http://sqoop.apache.org/
Available commands:
) Exit the shell
history (\H
) Display, manage and recall edit-line history
) Display this help message
(\st ) Configure various client options and settings
(\sh ) Display various objects and configuration options
(\cr ) Create new object in Sqoop repository
) Delete existing object in Sqoop repository
(\up ) Update objects in Sqoop repository
(\cl ) Create new object based on existing one
(\sta) Start job
(\stp) Stop job
(\stu) Display status of a job
(\en ) Enable object in Sqoop repository
disable (\di ) Disable object in Sqoop repository
For help on a specific command type: help command
我们在使用的过程中可能会遇到错误,使用以下命令来使错误信息显示出来
sqoop:000& set option --name verbose --value true
sqoop:000& set server --host udh-yf-
Server is set successfully
对象(连接
已经注册的
connectors:
sqoop:000& show connector
+----+------------------------+-----------------+------------------------------------------------------+----------------------+
| Supported Directions |
+----+------------------------+-----------------+------------------------------------------------------+----------------------+
| kite-connector
| 1.99.5-cdh5.4.3 | org.apache.sqoop.connector.kite.KiteConnector
| kafka-connector
| 1.99.5-cdh5.4.3 | org.apache.sqoop.connector.kafka.KafkaConnector
| hdfs-connector
| 1.99.5-cdh5.4.3 | org.apache.sqoop.connector.hdfs.HdfsConnector
| generic-jdbc-connector | 1.99.5-cdh5.4.3 | org.apache.sqoop.connector.jdbc.GenericJdbcConnector | FROM/TO
+----+------------------------+-----------------+------------------------------------------------------+----------------------+
这里我们利用
Generic JDBC Connector
对象,下面创建的是连接
sqoop:000& create link -c 4
,表明创建的是一个
generic jdbc connector
Creating link for connector with id 4
Please fill following values to create new link object
Name: mysql-link
Link configuration
JDBC Driver Class: com.mysql.jdbc.Driver
JDBC Connection String: jdbc:mysql://20.12.20.14:3306/hive
jdbc:mysql://
Username: root
Password: ******
JDBC Connection Properties:
There are currently 0 values in the map:
entry# protocol=tcp
There are currently 1 values in the map:
protocol = tcp
New link was successfully created with validation status OK and persistent id 1
sqoop:000& show link
+----+------------+--------------+------------------------+---------+
| Connector Id |
Connector Name
| Enabled |
+----+------------+--------------+------------------------+---------+
| mysql-link | 4
| generic-jdbc-connector | true
+----+------------+--------------+------------------------+---------+
上面,我们成功创建了一个
接下来我们为
hdfs connector
sqoop:000& create link -c 3
Creating link for connector with id 3
Please fill following values to create new link object
Name: hdfs-link
Link configuration
HDFS URI: hdfs://udh-yf-:8020
New link was successfully created with validation status OK and persistent id 2
已经成功创建了
Connectors
用于读取数据,
用于写入数据。使用上面的
show connector -all
命令可以显示出
Generic JDBC Connector
都是支持的。也就是说我们既可以从数据库中读取数据,也可以往数据库中写入数据。为了创建一个
,我们需要指定
部分可以使用
最后,我们可以使用这两个
部分。说的通俗一点,就是我们需要从哪里
把这些数据导入
读数据导入到
sqoop:000& create job -f 1 -t 2
Creating job for links with from id 1 and to id 2
Please fill following values to create new job object
Name: mysql-hdfs
From database configuration
Schema name: hive
必填,数据库名称
Table name: TBLS
必填,表名
Table SQL statement:
Table column names:
Partition column name:
Null value allowed for the partition column:
Boundary query:
ToJob configuration
Override null value:
Null value:
Output format:
0 : TEXT_FILE
1 : SEQUENCE_FILE
Compression format:
1 : DEFAULT
2 : DEFLATE
7 : SNAPPY
8 : CUSTOM
Custom compression format:
Output directory: /tmp/tbls
Throttling resources
Extractors: 2
可选,对应
Loaders: 1
可选,对应
New job was successfully created with validation status OK
and persistent id 1
这样就建立了一个新的
可以使用以下命令来执行
代表上面创建的
,可以使用
来查看已经创建的
sqoop:000& start job -j 1 -s
# hadoop fs -cat /tmp/tbls/33ccf4ab-8531-45cf-bf45-b046afdb9ff6.txt
3,,1,0,'hue',0,3,'test','MANAGED_TABLE',NULL,NULL,NULL
4,,1,0,'hue',0,4,'test01','MANAGED_TABLE',NULL,NULL,NULL
5,,1,0,'hue',0,5,'test02','MANAGED_TABLE',NULL,NULL,NULL
1,aaaaaaa,bbbbbb
2,ccccccc,dddddd
3,eeeeeee,ffffff
同样我们可以根据上面已创建的两个
上数据导出到
的表中,只需重新创建一个
sqoop:000&
create job -f 2 -t 1
Creating job for links with from id 2 and to id 1
Please fill following values to create new job object
Name: hdfs-mysql
From Job configuration
Input directory: /tmp/test.txt
Override null value:
Null value:
To database configuration
Schema name: hive
Table name: test1
Table SQL statement:
Table column names:
Stage table name:
Should clear stage table:
Throttling resources
Extractors: 2
Loaders: 1
New job was successfully created with validation status OK
and persistent id 2
这样就建立了一个新的
sqoop:000& start job -j 2 -s
mysql& select * from test1;
+------+---------+--------+
+------+---------+--------+
1 | aaaaaaa | bbbbbb |
2 | ccccccc | dddddd |
3 | eeeeeee | ffffff |
+------+---------+--------+
4 rows in set (0.00 sec)
(application/vnd.openxmlformats-officedocument.wordprocessingml.document)
(application/vnd.openxmlformats-officedocument.wordprocessingml.document)

我要回帖

更多关于 icloud邮箱 的文章

 

随机推荐