2.环境变量配置
vi ~/.bash_profile
export SQOOP_HOME=/home/hadoop/sqoop-1.4.6复制conf/sqoop-env-template.sh 为:conf/sqoop-env.sh
# Hadoop
export HADOOP_PREFIX=/home/hadoop/hadoop-2.6.0
export HADOOP_HOME=${HADOOP_PREFIX}
export PATH=$PATH:$HADOOP_PREFIX/bin:$HADOOP_PREFIX/sbin
export HADOOP_COMMON_HOME=${HADOOP_PREFIX}
export HADOOP_HDFS_HOME=${HADOOP_PREFIX}
export HADOOP_MAPRED_HOME=${HADOOP_PREFIX}
export HADOOP_YARN_HOME=${HADOOP_PREFIX}
# Native Path
export HADOOP_COMMON_LIB_NATIVE_DIR=${HADOOP_PREFIX}/lib/native
export HADOOP_OPTS="-Djava.library.path=$HADOOP_PREFIX/lib/native"
# Hadoop end
#Hive
export HIVE_HOME=/home/hadoop/hive-1.2.1
export PATH=$HIVE_HOME/bin:$PATH
#HBase
export HBASE_HOME=/home/hadoop/hbase-1.1.2
export PATH=$HBASE/bin:$PATH
4.复制mysql驱动
将mysql的驱动jar(mysql-connector-java-5.1.34.jar)复制到lib目录下
二、hive导入测试
sqoop ##sqoop命令
import ##表示导入
--connect jdbc:mysql://ip:3306/sqoop ##告诉jdbc,连接mysql的url
--username root ##连接mysql的用户名
--password 123456 ##连接mysql的密码
--table test ##从mysql导出的表名称
--query ##查询语句
--columns ##指定列
--where ##条件
--hive-import ##指定为hive导入
--hive-table ##指定hive表,可以使用--target-dir //user/hive/warehouse/table_name 替换
--fields-terminated-by '\t' ##指定输出文件中的行的字段分隔符
-m 1 ##复制过程使用1个map作业
以上的命令中后面的##部分是注释,执行的时候需要删掉;另外,命令的所有内容不能换行,只能一行才能执行。以下操作类似。
准备数据
CREATE TABLE `t_user` (
`id` varchar(40) COLLATE utf8_bin NOT NULL,
`name` varchar(40) COLLATE utf8_bin NOT NULL,
`age` int(11) DEFAULT NULL,
PRIMARY KEY (`id`)
);
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
INSERT t_user VALUES(uuid_short(), CONCAT('姓名',ROUND(RAND()*50)), ROUND(RAND()*100));
1.导入数据到HDFS
参考文章:
1.sqoop的安装与使用
2.Sqoop安装配置及演示