Into HDFS
Import All
sqoop import \
--connect jdbc:mysql://hadoop01:3306/test1 \
--username root \
--password 1234 \
--table students \
--target-dir /user/test1 \
--delete-target-dir \
--num-mappers 1 \
--fields-terminated-by '\t'
Queries Import
sqoop import \
--connect jdbc:mysql://hadoop01:3306/test1 \
--username root \
--password 1234 \
--target-dir /user/test1 \
--delete-target-dir \
--m 1 \
--fields-terminated-by '\t' \
--query 'select * from students where $CONDITIONS'
Note: SQL end of the statement must be added $ CONDITIONS
Import of the specified column
sqoop import \
--connect jdbc:mysql://hadoop01:3306/test1 \
--username root \
--password 1234 \
--table students \
--target-dir /user/test1 \
--delete-target-dir \
--num-mappers 1 \
--fields-terminated-by '\t' \
--columns id,sex
Tip: the Columns If it comes to multiple columns, separated by commas, do not add spaces when separated
Keyword filtering query to import data
sqoop import \
--connect jdbc:mysql://hadoop01:3306/test1 \
--username root \
--password 1234 \
--table students \
--target-dir /user/test1 \
--delete-target-dir \
--num-mappers 1 \
--fields-terminated-by '\t' \
--where "id=2"
Imported into the Hive
1. directly into hive
sqoop import \
--connect jdbc:mysql://hadoop01:3306/test1 \
--username root \
--password 1234 \
--table students \
--m 1 \
--hive-import \
--fields-terminated-by "\t" \
--hive-overwrite \
--hive-table students
Tip: Hive in the table to the presence, absence does not automatically create
2. The load is then introduced into the HDFS to Hive
1. introduced into HDFS
sqoop import \
--connect jdbc:mysql://hadoop01:3306/test1 \
--username root \
--password 1234 \
--table students \
--target-dir /user/test1 \
--delete-target-dir \
--num-mappers 1 \
--fields-terminated-by '\t'
2.load to Hive
load data inpath '/user/test1' into table hive表名字
Export to MySQL
sqoop export \
--connect jdbc:mysql://hadoop01:3306/test1 \
--username root \
--password 1234 \
--export-dir /user/test1 \
--table students \
--input-fields-terminated-by '\t'
--m 1
Tip: When you export data MySQL tables must exist