12、sqoop
Apache Sqoop(TM) is a tool designed for efficiently transferring bulk data between Apache Hadoop and structured datastores
such as relational databases.
hdfs <----> 关系型数据库 相互传
# 1.4.6 版本
配置/etc/profile
1、mv sqoop-env.templete.sh sqoop-env.sh 2、将要操作的MySQL的驱动包,拷贝到 lib下
测试
sqoop version
sqoop list-databases --connect jdbc:mysql://node01:3306 --username root --password 123

Import

mysql->hdfs
sqoop import --connect jdbc:mysql://node01:3306 --username root --password 123 --as-textfile --columns id,name --delete-target-dir
-m 1 --table table_1 --target-dir /sqoop
从mysql 导入到hdfs
或者
sqoop --options-file option.txt
import --connect jdbc:mysql://node01:3306/db --username root --password 123 --as-textfile --columns id,name
--where
"name='STRING' " --delete-target-dir -m 1 --table table_1 --target-dir /sqoop
import --connect jdbc:mysql://node01:3306/db --username root --password 123 --as-textfile
--delete-target-dir -m 1--target-dir
/sqoop
-e
select * from table_1 where id >20 and $CONDITIONS
--split-by
name
会转换为 and (1=0)
mysql->hive

import --connect jdbc:mysql://node01:3306/db --username root --password 123 --as-textfile
--columns
id,name,version -m 1
--table
table_1
--hive-import
--create-hive-table
--hive-table
hive_table_1
--fields-terminated-by
,
--lines-terminated-by "\n" \
--hive-overwrite \
--delete-target-dir \
--hive-database myhive \
--hive-table new_help_keyword2
--target-dir /user/root/myimport3 \
--incremental append \
--check-column help_keyword_id \
--last-value 500 \
-m 1
# 默认导出没有分隔符
实际:
1、将MySQL导入hdfs
2、将hdfs导入hive
mysql-hbase

hbase 和 sqoop的版本要严格对应
import --connect jdbc:mysql://node01:3306/db --username root --password 123 --as-textfile--columns id,name,version -m 1 --table table_1 --column-family
cf
--hbase-create-table
--hbase-row-key
id
--hbase-table
hbase_table_1
export
hive->mysql
export --connect jdbc:mysql://node01:3306/re --username root --password 1234 --columns id,name --export-dir /usr/hive_remote/table/t1-m 1 --table test
--input-fields-teminated-by
^A

浙公网安备 33010602011771号