sqoop学习笔记

来源:互联网 发布:重庆八中数据谷中学 编辑:程序博客网 时间:2024/05/16 10:48
1.下面是个从数据库导出表的数据到HDFS上文件的例子(-m 1 表示主键或序列化信息):
 sqoop import --connect jdbc:mysql://127.0.0.1:3306/hive --username root --password root --table customer -m 1

 sqoop import --connect jdbc:mysql://127.0.0.1/hive?user=root --table customer -m 1
 
2.列出mysql中的表名:
sqoop list-tables --connect jdbc:mysql://127.0.0.1:3306/hive --username root --password root

3.将mysql中的表导入hive中:
$ sqoop import --connect jdbc:mysql://IP:PORT/DATABASE --username USERNAME --password PASSWORD --table TABLE --hive-import  

如果曾经执行失败过,那再执行的时候,会有错误提示:
ERROR tool.ImportTool: Encountered IOException running import job: org.apache.hadoop.mapred.FileAlreadyExistsException:
Output directory xxx already exists
执行 $HADOOP_HOME/bin/hadoop fs -rmr customer 即可

参考链接:
http://www.ibm.com/developerworks/cn/data/library/techarticle/dm-1212liuqy/

http://blog.csdn.net/mozart_cai/article/details/8831249

http://www.linuxidc.com/Linux/2013-04/83447p2.htm

sqoop-export --connect jdbc:mysql://localhost:3306/hive --username root --table t1 --export-dir /hbase

sqoop create-hive-table  --connect jdbc:mysql://127.0.0.1:3306/hive --username root --password root --table customer -P
原创粉丝点击