sqoop是让hadoop技术支持的clouder公司开发的一个在关系数据库和hdfs,hive之间数据导入导出的一个工具
下载地址:http://mirrors.hust.edu.cn/apache/sqoop/1.4.3/sqoop-1.4.3.bin__hadoop-1.0.0.tar.gz
另外,sqoop导入mysql数据运行过程中依赖mysql-connector-java-*.jar,
1.sqoop的安装目录是 /usr/local/hadoop/sqoop/
cp /usr/local/hadoop/lib/mysql-connector-java-5.1.22-bin.jar /usr/local/hadoop/sqoop/mysql-connector-java-5.1.22-bin.jar 支持导入mysql数据
2.修改conf目录下的配置文件
cp /usr/local/hadoop/sqoop/conf/sqoop-env-template.sh /usr/local/hadoop/sqoop/conf/sqoop-env.sh
#Set path to where bin/hadoop is available
export HADOOP_COMMON_HOME=/usr/local/hadoop
export HADOOP_HOME=/usr/local/hadoop
#Set path to where hadoop-*-core.jar is available
#export HADOOP_MAPRED_HOME=
#set the path to where bin/hbase is available
#export HBASE_HOME=
#Set the path to where bin/hive is available
export HIVE_HOME=/usr/local/hadoop/hive
红色是要添加的
source /usr/local/hadoop/sqoop/conf/sqoop-env.sh //设置环境变量生效
2.修改sqoop-site-template.xml文件
mv sqoop-site-template.xml sqoop-site.xml
3.从mysql中导数据到hdfs和hive中
sqoop import --verbose --fields-terminated-by ',' --connect jdbc:mysql://localhost:3306/yg_main --table item --username root --password root --hive-import --warehouse-dir 001 --fields-terminated-by ',' --hive-table default.item