作者:Loves_dccBigData
文章目录- Sqoop系列文章目录
- 前言
- 1、MySQL数据 -->HDFS //import
- 2、MySQL数据 -->Hive //import
- 3、MySQL数据 -->Hbase //import
- 总结
前言
提示:以下是本篇文章正文内容
1、MySQL数据 -->HDFS //import编写脚本MySQLToHDFS.conf
import --connect jdbc:mysql://master:3306/student?useSSL=false --username root --password 123456 --table student --m 2 --split-by age --target-dir /sqoop/data/student1 --fields-terminated-by ',' --delete-target-dir
执行脚本
sqoop --options-file MySQLToHDFS.conf
注意事项
1)、–m 表示指定生成多少个Map任务,不是越多越好,因为MySQL Server的承载能力有限
2)、当指定的Map任务数>1,那么需要结合–split-by参数,指定分割键,以确定每个map任务到底读取哪一部分数据,最好指定数值型的列,最好指定主键(或者分布均匀的列=>避免每个map任务处理的数据量差别过大)
3)、如果指定的分割键数据分布不均,可能导致数据倾斜问题 4)、分割的键最好指定数值型的,而且字段的类型为int、bigint这样的数值型
5)、编写脚本的时候,注意:例如:–username参数,参数值不能和参数名同一行
7)、实际上sqoop在读取mysql数据的时候,用的是JDBC的方式,所以当数据量大的时候,效率不是很高
8)、sqoop底层通过MapReduce完成数据导入导出,只需要Map任务,不需要Reduce任务 9)、每个Map任务会生成一个文件
**
–delete-target-dir 参数可以直接删除目录直接执行
–direct 参数可以在导出MySQL数据的时候,使用MySQL提供的导出工具mysqldump,加快导出速度,提高效率
#需要将master上的/usr/bin/mysqldump分发至 node1、node2的/usr/bin目录下 scp /usr/bin/mysqldump node1:/usr/bin/ scp /usr/bin/mysqldump
node2:/usr/bin/
**
2、MySQL数据 -->Hive //import先会将MySQL的数据导出来并在HDFS上找个目录临时存放,默认为:/user/用户名/表名,然后再将数据加载到Hive中,加载完成后,会将临时存放的目录删除
编写脚本MySQLToHIVE.conf
import --connect jdbc:mysql://master:3306/student?useSSL=false --username root --password 123456 --table score --fields-terminated-by "t" --lines-terminated-by "n" --m 3 --split-by student_id --hive-import --hive-overwrite --create-hive-table --hive-database testsqoop --hive-table score --delete-target-dir
执行脚本
sqoop --options-file MySQLToHIVE.conf
-e参数的使用:查询语句
import --connect jdbc:mysql://master:3306/student --username root --password 123456 --fields-terminated-by "t" --lines-terminated-by "n" --m 2 --split-by student_id --e "select * from score where student_id=1500100011 and $CONDITIONS" --target-dir /testQ --hive-import --hive-overwrite --create-hive-table --hive-database testsqoop --hive-table score23、MySQL数据 -->Hbase //import
编写脚本MySQLToHbase.conf
import --connect jdbc:mysql://master:3306/student?useSSL=false --username root --password 123456 --table student --hbase-table student --hbase-create-table --hbase-row-key id --m 1 --column-family cf1 在Hbase中创建表 create 'student','cf1'
执行脚本
sqoop --options-file MySQLToHbase.conf总结
提示:这里对文章进行总结:
以上是对自己所学的内容的总结,仅仅简单介绍了sqoop的基本知识点的使用,需要自己去敲大量代码,不断的练习,希望这些知识可以对学习者有作用.



