- Mysql 测试数据
create database sqooptest; Use sqooptest create table person(pid int primary key auto_increment, name varchar(20), sex varchar(20)); insert into person(name, sex) values('james', 'Male'); insert into person(name, sex) values('lison', 'Female');
- 全量导入
sqoop import \ --connect jdbc:mysql://192.168.244.100:3306/sqooptest \ --username root \ --password root1234% \ --table person \ --target-dir /user/person \ --delete-target-dir \ --num-mappers 1 \ --fields-terminated-by "," hadoop fs -cat /user/person/part-m-00000
- 带查询条件导入:
$CONDITIONS
不能省略, 要链接 sqoop 默认的条件sqoop import \ --connect jdbc:mysql://192.168.244.100:3306/sqooptest \ --username root \ --password root1234% \ --target-dir /user/person \ --delete-target-dir \ --num-mappers 1 \ --fields-terminated-by "," \ --query 'select name,sex from person where pid <=1 and $CONDITIONS;' hadoop fs -cat /user/person/part-m-00000
- 导入特定列
sqoop import \ --connect jdbc:mysql://192.168.244.100:3306/sqooptest \ --username root \ --password root1234% \ --target-dir /user/person \ --delete-target-dir \ --num-mappers 1 \ --fields-terminated-by "," \ --columns pid,sex \ --table person
上一篇
Hadoop-Sqoop-Hive与Mysql互导
2023-04-23
下一篇
Hadoop-Sqoop-安装
2023-04-23