sqoop安装后找不到hive.HiveConf类解决办法

  • 遇到错误,找不到hive.HiveConf…
    直接将hive安装目录中的lib中的hive-common-2.3.5.jar 拷贝到sqoop的lib中
    然后测试,如果通过,则恭喜你!!!!你人品爆棚!

  • 如果人品不行,按下列步骤,一步步照搬!!!九九八十一难!

    • 1.按正常流程先安装sqoop解压,修改sqoop-env.sh
      export HADOOP_COMMON_HOME=/opt/apps/hadoop2
      export HADOOP_MAPRED_HOME=/opt/apps/hadoop2
      export HIVE_HOME=/opt/apps/hive2

    • 2.要在/root/.bash_profile中添加一句话:
      export HIVE_HOME=/opt/apps/hive2
      export HADOOP_CLASSPATH= H A D O O P C L A S S P A T H : HADOOP_CLASSPATH: HADOOPCLASSPATH:HIVE_HOME/lib/*

    • 3.要在jdk的权限安全配置中添加如下配置:
      vi /opt/apps/jdk/jre/lib/security/java.policy
      在最后添加:
      grant{
      permission javax.management.MBeanTrustPermission “register”;
      };

    • 4.替换版本冲突的jar包
      把sqoop的lib中的所有jackson-.jar重命名 jackson-.jar.bak
      然后将hive中的lib中的所有jackson-*.jar 拷贝到sqoop的lib中

    • 5.把hive的hive-site.xml拷贝到sqoop的conf目录中

sqoop使用
测试命令:列出mysql中所有的库、表
	sqoop list-databases --connect jdbc:mysql://doit03:3306 --username root --password root
	sqoop list-tables --connect jdbc:mysql://doit03:3306/doit_mall --username root --password root
测试命令:从mysql中导入数据到hdfs的指定目录
并行度的问题补充:一个maptask从mysql中获取数据的速度约为4-5m/s,而mysql服务器的吞吐量40-50M/s
那么,在mysql中的数据量很大的场景下,可以考虑增加maptask的并行度来提高数据迁移速度
-m就是用来指定maptask的并行度
思考:maptask一旦有多个,那么它是怎么划分处理任务?
	sqoop import \
	--connect jdbc:mysql://localhost:3306/db \
	--username root \
	--password root \
	--table oms_order \
	--target-dir /sqooptest1  \
	--fields-terminated-by ',' \
	--split-by id \
	#如果目标路径已存在则删除
	--delete-target-dir \
	-m 2
如果没有数字主键,也可以使用文本列来作为切分task的参照,但是需要增加一个-D参数,如下
	sqoop import -Dorg.apache.sqoop.splitter.allow_text_splitter=true \
	--connect jdbc:mysql://doit03:3306/doit_mall \
	--username root \
	--password root \
	--table noid \
	--target-dir /sqooptest3  \
	--fields-terminated-by ',' \
	--split-by name \
	-m 2 
导入mysql数据到hive
	sqoop import \
	--connect jdbc:mysql://doit03:3306/doit_mall \
	--username root \
	--password root \
	--table oms_order \
	--hive-import \
	--hive-table xdb.oms_order \
	--delete-target-dir \
	--split-by id \
	--as-textfile \
	--null-string 'NaN' \
	--null-non-string 'NaN' \
	--compress   \
	--compression-codec gzip \
	-m 2
条件导入: --where
	sqoop import \
	--connect jdbc:mysql://doit03:3306/doit_mall \
	--username root \
	--password root \
	--table oms_order \
	--hive-import \
	--hive-table oms_order_3 \
	--where "id>20 and note='xxx'" \
	--fields-terminated-by ',' \
	--split-by id \
	-m 2 
条件导入: --columns
	sqoop import \
	--connect jdbc:mysql://doit03:3306/doit_mall \
	--username root \
	--password root \
	--table oms_order \
	--hive-import \
	--hive-table oms_order_4 \
	--where "id>20" \
	--columns "id,receiver_province,receiver_city,receiver_region" \
	--fields-terminated-by ',' \
	--split-by id \
	-m 2 
条件导入: --query 
query自由查询导入时,sql语句中必须带 $CONDITIONS条件 :  where $CONDITIONS   ,要么  where id>20  and $CONDITIONS
为什么呢?因为sqoop要将你的sql语句交给多个不同的maptask执行,每个maptask执行sql时肯定要按任务规划加范围条件,
所以就提供了这个$CONDITIONS作为将来拼接条件的占位符
	sqoop import \
	--connect jdbc:mysql://doit03:3306 \
	--username root \
	--password root \
	--target-dir /xx5 \
	--hive-import \
	--hive-table oms_order_7 \
	#有双引号的里面的单引号无转义
	--query 'select id,member_id,order_sn,receiver_province from doit_mall.oms_order where id>20 and $CONDITIONS' \
	--fields-terminated-by ',' \
	--split-by id \
	-m 2 
query可以支持复杂查询(包含join、子查询、分组查询)但是,一定要去深入思考你的sql的预期运算逻辑和maptask并行分任务的事实!

sqoop import \
--connect jdbc:mysql://doit03:3306/doit_mall \
--username root \
--password root \
--target-dir /xx5 \
--delete-target-dir \
--hive-import \
--hive-table oms_order_amt \
--query 'select order_id,sum(product_price*product_quantity) as amt from oms_order_item where $CONDITIONS group by order_id' \
--fields-terminated-by ',' \
#改成id报错 join 操作是在mysql 中完成的(并且mysql join会增加mysql压力) sqoop只是分配任务
--split-by order_id \
-m 2 
##全量导入适合数据小 如果用增量 修改和删除join时导致数据多出或缺少
## --增量导入 --根据一个递增字段来界定增量数据 用拉链表实现
sqoop import \
--connect jdbc:mysql://doit03:3306/doit_mall \
--username root \
--password root \
--table demo \
--hive-import \
--hive-table demo \
--split-by id \
--incremental append \
--check-column id \
--last-value 4 \
-m 2 

## --增量导入 --根据修改时间来界定增量数据,要求必须有一个时间字段,且该字段会跟随数据的修改而修改
sqoop import \
--connect jdbc:mysql://doit03:3306/doit_mall \
--username root \
--password root \
--table demo \
--target-dir /demo2 \
--split-by id \
--incremental lastmodified \
--check-column update_time \
--last-value '2019-09-01 06:26:59.0' \
--merge-key id \    #不光会将增量数据导入hdfs,而且会将以前导入的和最近一次导入的数据用一个mr job来合并
# --append    不断将增量数据往目标目录中追加文件
--fields-terminated-by ',' \
-m 1 


## 附录:  数据导入参数大全!
Table 3. Import control arguments:
Argument	Description
--append	Append data to an existing dataset in HDFS
--as-avrodatafile	Imports data to Avro Data Files
--as-sequencefile	Imports data to SequenceFiles
--as-textfile	Imports data as plain text (default)
--as-parquetfile	Imports data to Parquet Files
--boundary-query <statement>	Boundary query to use for creating splits
--columns <col,col,col…>	Columns to import from table
--delete-target-dir	Delete the import target directory if it exists
--direct	Use direct connector if exists for the database
--fetch-size <n>	Number of entries to read from database at once.
--inline-lob-limit <n>	Set the maximum size for an inline LOB
-m,--num-mappers <n>	Use n map tasks to import in parallel
-e,--query <statement>	Import the results of statement.
--split-by <column-name>	Column of the table used to split work units. Cannot be used with --autoreset-to-one-mapper option.
--split-limit <n>	Upper Limit for each split size. This only applies to Integer and Date columns. For date or timestamp fields it is calculated in seconds.
--autoreset-to-one-mapper	Import should use one mapper if a table has no primary key and no split-by column is provided. Cannot be used with --split-by <col> option.
--table <table-name>	Table to read
--target-dir <dir>	HDFS destination dir
--temporary-rootdir <dir>	HDFS directory for temporary files created during import (overrides default "_sqoop")
--warehouse-dir <dir>	HDFS parent for table destination
--where <where clause>	WHERE clause to use during import
-z,--compress	Enable compression
--compression-codec <c>	Use Hadoop codec (default gzip)
--null-string <null-string>	The string to be written for a null value for string columns
--null-non-string <null-string>	The string to be written for a null value for non-string columns



## sqoop导出数据 默认模式是插入, 会出现主键冲突现象
sqoop  export \
--connect jdbc:mysql://doit03:3306/doit_mall \
--username root \
--password root \
--table person \
--export-dir '/export/' \
--input-null-string 'NaN' \
--input-null-non-string 'NaN' \
--batch


sqoop  export \
--connect jdbc:mysql://doit03:3306/doit_mall \
--username root \
--password root \
--table person \
--export-dir '/export3/' \
--input-null-string 'NaN' \
--input-null-non-string 'NaN' \
--update-mode allowinsert  \
--update-key id \
--batch


## 附录:export控制参数列表
Table 29. Export control arguments:

Argument	Description
--columns <col,col,col…>	Columns to export to table
--direct	Use direct export fast path
--export-dir <dir>	HDFS source path for the export
-m,--num-mappers <n>	Use n map tasks to export in parallel
--table <table-name>	Table to populate
--call <stored-proc-name>	Stored Procedure to call
--update-key <col-name>	Anchor column to use for updates. Use a comma separated list of columns if there are more than one column.
--update-mode <mode>	Specify how updates are performed when new rows are found with non-matching keys in database.
Legal values for mode include updateonly (default) and allowinsert.
--input-null-string <null-string>	The string to be interpreted as null for string columns
--input-null-non-string <null-string>	The string to be interpreted as null for non-string columns
--staging-table <staging-table-name>	The table in which data will be staged before being inserted into the destination table.
--clear-staging-table	Indicates that any data present in the staging table can be deleted.
--batch	Use batch mode for underlying statement execution.

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值