Sqoop是一个用来将Hadoop和关系型数据库中的数据相互转移的工具,可以将一个关系型数据库(例如 : MySQL ,Oracle ,Postgres等)中的数据导进到Hadoop的HDFS中,也可以将HDFS的数据导进到关系型数据库中。
1、下载地址:
http://sqoop.apache.org/
2、修改SQOOP的文件configure-sqoop,注释掉hbase和zookeeper检查(除非你准备使用HABASE等HADOOP上的组件)
#if [ ! -d "${HBASE_HOME}" ]; then
# echo “Error: $HBASE_HOME does not exist!”
# echo ‘Please set $HBASE_HOME to the root of your HBase installation.’
# exit 1
#fi
#if [ ! -d "${ZOOKEEPER_HOME}" ]; then
# echo “Error: $ZOOKEEPER_HOME does not exist!”
# echo ‘Please set $ZOOKEEPER_HOME to the root of your ZooKeeper installation.’
# exit 1
#fi
还有其他HBASE和ZOOKEEPER的部分也需要注释掉。
3.在使用sqoop之前需要首先启动hadoop
4.常用的sqoop命令:
4.1 列出mysql数据库中的所有数据库
sqoop list-databases --connect jdbc:mysql://localhost:3306/ --username root --password 123456
4.2 连接mysql并列出数据库中的表
sqoop list-tables --connect jdbc:mysql://localhost:3306/test --username root --password 123456
4.3 将关系型数据的表结构复制到hive中,只是复制表的结构,表中的内容没有复制过去
bin/sqoop create-hive-table --connect jdbc:mysql://localhost:3306/test -table test_table -username root -password password -hive-table test_table
4.4 将数据库表数据导入到hdfs
bin/sqoop import --connect jdbc:mysql://localhost:3306/test --username root --password password --table test_table
--warehouse-dir /user/yr/ -m 1
4.5 将hdfs数据导入到数据库表
bin/sqoop export --connect jdbc:mysql://localhost:3306/test --username root --password password --table test_table
--export-dir /user/yr/test_table
4.6 将数据库表数据导入到hive
bin/sqoop import --connect jdbc:mysql://localhost:3306/test --username root --password password --table test_table
--hive-import --hive-table test_table -m 1
4.7 将hive数据导入到数据库表
bin/sqoop export --connect jdbc:mysql://localhost:3306/test --username root --password password --table test_table --export-dir /user/hive/warehouse/test_table
1、下载地址:
http://sqoop.apache.org/
2、修改SQOOP的文件configure-sqoop,注释掉hbase和zookeeper检查(除非你准备使用HABASE等HADOOP上的组件)
#if [ ! -d "${HBASE_HOME}" ]; then
# echo “Error: $HBASE_HOME does not exist!”
# echo ‘Please set $HBASE_HOME to the root of your HBase installation.’
# exit 1
#fi
#if [ ! -d "${ZOOKEEPER_HOME}" ]; then
# echo “Error: $ZOOKEEPER_HOME does not exist!”
# echo ‘Please set $ZOOKEEPER_HOME to the root of your ZooKeeper installation.’
# exit 1
#fi
还有其他HBASE和ZOOKEEPER的部分也需要注释掉。
3.在使用sqoop之前需要首先启动hadoop
4.常用的sqoop命令:
4.1 列出mysql数据库中的所有数据库
sqoop list-databases --connect jdbc:mysql://localhost:3306/ --username root --password 123456
4.2 连接mysql并列出数据库中的表
sqoop list-tables --connect jdbc:mysql://localhost:3306/test --username root --password 123456
4.3 将关系型数据的表结构复制到hive中,只是复制表的结构,表中的内容没有复制过去
bin/sqoop create-hive-table --connect jdbc:mysql://localhost:3306/test -table test_table -username root -password password -hive-table test_table
4.4 将数据库表数据导入到hdfs
bin/sqoop import --connect jdbc:mysql://localhost:3306/test --username root --password password --table test_table
--warehouse-dir /user/yr/ -m 1
4.5 将hdfs数据导入到数据库表
bin/sqoop export --connect jdbc:mysql://localhost:3306/test --username root --password password --table test_table
--export-dir /user/yr/test_table
4.6 将数据库表数据导入到hive
bin/sqoop import --connect jdbc:mysql://localhost:3306/test --username root --password password --table test_table
--hive-import --hive-table test_table -m 1
4.7 将hive数据导入到数据库表
bin/sqoop export --connect jdbc:mysql://localhost:3306/test --username root --password password --table test_table --export-dir /user/hive/warehouse/test_table