测试sqoop到mysql的连通性

查看数据库

bin/sqoop list-databases --connect jdbc:mysql://localhost:3306 --username root --password 123456

查看数据库mysql中存在的表

bin/sqoop list-tables --connect jdbc:mysql://localhost:3306/mysql --username root --password 123456

将数据库中的数据导入到HDFS
指定输出路径、指定数据分隔符

–fields-terminated-by ‘\t’

bin/sqoop import --connect jdbc:mysql://localhost:3306/test --username root --password 123456  --table student --target-dir /sqoop/mysql1 --fields-terminated-by '\t'
1
指定Map数量 -m

-m 2

bin/sqoop import --connect jdbc:mysql://localhost:3306/test --username root --password 123456  --table student --target-dir /sqoop/mysql2 --fields-terminated-by '\t' -m 2
1
增加where条件, 注意:条件必须用引号引起来

id大于3: --where ‘id>3’

bin/sqoop import --connect jdbc:mysql://localhost:3306/test --username root --password 123456  --table student --where 'id>3' --target-dir /sqoop/mysql3 --fields-terminated-by '\t'
1
增加query语句(使用 \ 将语句换行)

bin/sqoop import --connect jdbc:mysql://localhost:3306/test --username root --password 123456 \
--query 'SELECT * FROM student where id > 2 AND $CONDITIONS' --split-by student.id --target-dir /sqoop/mysql4

posted on 2025-03-30 22:11  leapss  阅读(10)  评论(0)    收藏  举报