Sqoop数据迁移

2018-09-28  本文已影响0人  hipeer

  1. 从RDB导入到HDFS
// 把表数据全部导出
sqoop import 
--connect jdbc:mysql://localhost/test_db 
--dirver com.mysql.jdbc.Driver 
--table users 
--usernsme root 
--password 123456 
--target-dir /temp/datahouse/test_db/users
-m 3

// 导出符符合where条件的数据
sqoop import 
--connect jdbc:mysql://localhost/test_db
--driver com.mysql.jdbc.Driver
--table users
--where "user_age < 18"
--username root
--password 123456
--target-dir /temp/datahouse/test_db/users
-m 3

// 导出指定列的数据
sqoop import 
--connect jdbc:mysql://localhost/test_db
--driver com.mysql.jdbc.Driver
--table users
--columns "user_id, user_name"
--username root
--password 123456
--target-dir /temp/datahouse/test_db/users
-m 3

// 导出查询出的数据
sqoop import
--connect jdbc:mysql://localhost/test_db
--driver com.mysql.jdbc.Driver
--query "select user_id, user_name from users where user_age < 18 \$CONDITIONS"
--split-by user_id
--username root
--password 123456
--target-dir /temp/datahouse/test_db/users
-m 3

// 增量导入
sqoop import 
--connect jdbc:mysql://localhost/test_db
--driver com.mysql.jdbc.Driver
--table users
--incermental append
--check-column "user_join_data"
--last-value "2018-09-20"
--username root
--password 123456
--target-dir /temp/datahouse/test_db/users
-m 3
  1. 从RDB导入到Hive
sqoop import 
--connect jdbc:mysql://localhost/test_db
--driver com.mysql.jdbc.Driver
--query "select user_id, user_name, user_gender
              from users where user_age >= 18 and user_age <= 25 
              and \$CONDITIONS"
--spilt-by user_id
--username root 
--password 123456
--hive-import 
--create-hive-table
--hive-table test_db.users
--hive-partition-key "user_city"
--hive-partition-value "beijing"
--hive-overwrite
--target-dir /temp/datahouse/test_db/users
--delete-target-dir
-m 1

注:
往hive导入数据之前需要创建好database
--delete-target-dir 如果目标文件已存在就把它删除
--hive-partition-key 的值不能是sql中查询的字段
--target-dir 指定的目录下面并没有数据文件,数据文件被放在了hive的默认/apps/hive/warehouse下面

  1. 从RDB导入到HBase
sqoop import 
--connect jdbc:mysql://localhost/test_db
--username root 
--password 123456
--table users
--columns "user_id, user_name, user_city" 
--hbase-table users
--column-family personInfo
--hbase-row-key user_id
-m 1
上一篇下一篇

猜你喜欢

热点阅读