sqoop installation steps

sqoop installation steps:
cd /usr/local/
rz above file
Extracting tar xzvf sqoop146n.tar.gz
Configuration environment variable vi / etc / profile
Build environment variable source / etc / profile
The easiest to use documentation
1) displays a list of mysql database
Show all tables in the database:
Test Case:
The establishment of test table:
Insert test data:
insert into test values ​​(1, 'Beijing');
insert into test values ​​(2, 'Nanjing');
insert into test values ​​(3, 'Tokyo');
insert into test values (4,'西京');
insert into test values ​​(5, 'Xinjiekou');
insert into test values ​​(6, 'Wudaokou');
insert into test values ​​(7, 'Caishikou');
insert into test values ​​(8, 'plum city mouth');
insert into test values (9,'珠市口');
insert into test values (10,'磁器口');
 
 
此表为空表,仅做导回测试用
 
(1)mysql导入到hdfs
把mysql中表test导入到hdfs,导入之前查询一下test表中的数据
 
sqoop import --connect jdbc:mysql://hadoop:3306/test --username root --password root --table test -m 1
-m 表示Map并发数
若是不写--target-dir 则默认是hdfs上的/user/username/tablename 路径
 
(2)HDFS导入到mysql
 
把HDFS中数据导入到Mysql表中,mysql中需要预先建立空表test2,此时该表为空
输入:
如果中文乱码
 
 
(3) MYSQL-HIVE
可用(MYSQL->HIVE)
 
 
 
 
RDBMS-HDFS<>HIVE
 
多表导入 尽量不要用
sqoop import-all-tables --connect jdbc:mysql://hadoop:3306/test --username root --password root --as-textfile --warehouse-dir /output/
sqoop import-all-tables --connect jdbc:mysql://hadoop:3306/test --username root --password root --hive-import --as-textfile --create-hive-table -hive-table testsum -m 1
 
sqoop import \
--connect jdbc:mysql://hadoop1:3306/mysql \
--username root \
--password root \
--table x \
--fields-terminated-by "\t" \
--lines-terminated-by "\n" \
--hive-import \
--hive-overwrite \
--create-hive-table \
--delete-target-dir \
--hive-database mydb_test \
--hive-table uplooking1
 
 
sqoop import \
--connect jdbc:mysql://hadoop1:3306/mysql \
--username root \
--password root \
--table x \
--fields-terminated-by "\t" \
--lines-terminated-by "\n" \
--hive-import \
--hive-overwrite \
--create-hive-table \
--hive-table mydb_test.uplooking1 \
--delete-target-dir
 
 
SQOOP-HBASE
 
sqoop import -D sqoop.hbase.add.row.key=true --connect jdbc:mysql://192.168.16.100:3306/uplooking --username root --password root --table test --columns id,name --hbase-create-table --hbase-table test_mydb --column-family info --hbase-row-key ID --where "ID >= 10" -m 1
 
sqoop import \
--connect jdbc:mysql://hadoop1:3306/mysql \
--username root \
--password root \
--table x \
--hbase-table uplooking1 \
--column-family person \
--hbase-row-key x_id
 
(HIVE/HDFS->MYSQL) 万金油语句
 
sqoop-export \
--connect jdbc:mysql://hadoop:3306/test \ 连接名
--username root \ 用户
--password root \ 密码
--table b \ 导入的表
--export-dir /usr/hive/warehouse/a \ 导出文件目录
--columns id,name \ 导出字段 自主选择 如果不加则默认为全表导出
--update-mode allowinsert \ 从这开始以下均不需要考虑
--update-key category_id \
--fields-terminated-by '\001' \
--lines-terminated-by '\n' \
--input-null-string '\\N' \
--input-null-non-string '\\N'

Guess you like

Origin www.cnblogs.com/dasiji/p/11246040.html