Har*_*ris 3 sql-server hadoop hive sandbox sqoop
如何使用Sqoop将数据从关系数据库导入Sandbox中的Hive.我在MY PC中安装了Horton Works沙箱.我想知道这个迁移.我已经参考了这个链接http://hortonworks.com/kb/using-apache-sqoop-for-data-import-from-relational-dbs/ 但是我对一些疑问感到困惑1,是否需要任何Sqoop软件才能运行?2,在上面的mensioned链接中有一些代码在哪里我会把这段代码?在Hive查询窗口中?3,是否可以完全(或仅在时间表)迁移数据库?4,存储过程和Viwes会保留所有这些内容吗?
Sqoop预装了最新的Horton Sandbox.你必须做以下事情.如果某些情况,您可能需要权限(不允许主机'xxx.xx.xxx.xxx'连接到此MySQL服务器).否则执行以下操作 - 从RDBMS(MYSQL,ORACLE等)导入和导出数据到HDFS/HIVE/HBASE
先决条件
对于所有RDBMS,连接URL更改和剩余的所有命令行参数保持不变.您需要下载特定的JDBC/ODBC连接器JAR并将其复制到$ SQOOP_HOME/lib
MySQL的
下载mysql-connector-java.jar并放在$ SQOOP_HOME/lib文件夹中
cp mysql-connector-java-5.1.18-bin.jar /usr/local/hadoop/sqoop-1.4.3-cdh4.4.0/lib/
期待你在MySQL表中有数据.
从SQOOP中检索MySQL中可用的数据库列表
sqoop list-databases --connect jdbc:mysql://localhost:3306/ --username root -P
Run Code Online (Sandbox Code Playgroud)
MySQL到HDFS导入
有主键:
sqoop import -connect jdbc:mysql://localhost:3306/db1 -username root -password password --table tableName --target-dir /path/to/directoryName
Run Code Online (Sandbox Code Playgroud)
没有主键:
sqoop import -connect jdbc:mysql://localhost:3306/db1 -username root -password password --table tableName --target-dir /path/to/directoryName -m 1
Run Code Online (Sandbox Code Playgroud)
MySQL到Hive导入
有主键:
sqoop-import --connect jdbc:mysql://localhost:3306/db1 -username root -password password --table tableName --hive-table tableName --create-hive-table --hive-import --hive-home path/to/hive_home
Run Code Online (Sandbox Code Playgroud)
没有主键:
sqoop-import --connect jdbc:mysql://localhost:3306/db1 -username root -password password --table tableName --hive-table tableName --create-hive-table --hive-import --hive-home path/to/hive_home -m 1
Run Code Online (Sandbox Code Playgroud)
MySQL到HBase导入
有导入所有列:
sqoop import --connect jdbc:mysql://localhost:3306/db1 --username root --password root --table tableName --hbase-table hbase_tableName --column-family hbase_table_col1 --hbase-create-table
Run Code Online (Sandbox Code Playgroud)
HBase导入几列
sqoop import --connect jdbc:mysql://localhost:3306/db1 --username root --password root --table tableName --hbase-table hbase_tableName --columns column1,column2 --column-family hbase_table_col1 --hbase-create-table
Run Code Online (Sandbox Code Playgroud)
使用主键到HBase:
sqoop import --connect jdbc:mysql://localhost:3306/db1 --username root --password root --table tableName --hbase-table hbase_tableName --column-family hbase_table_col1 --hbase-row-key column1 –hbase-create-table
Run Code Online (Sandbox Code Playgroud)
没有主键的Hbase:
sqoop import --connect jdbc:mysql://localhost:3306/db1 --username root --password root --table tableName --hbase-table hbase_tableName --columns column1,column2 --column-family hbase_table_col --hbase-row-key column1 --hbase-create-table
Run Code Online (Sandbox Code Playgroud)
从HDFS导出到MySQL:
对于所有Hive/HBase/HDFS也是如此:因为Hive表只是HDFS中的目录.所以你只是将目录导出到MySQL
sqoop export --connect jdbc:mysql://localhost:3306/test_db --table tableName --export-dir /user/hive/warehouse/tableName --username root --password password -m 1 --input-fields-terminated-by '\001'
Run Code Online (Sandbox Code Playgroud)
SQL Server
连接网址:
sqoop import --connect'jdbc:sqlserver://; username = dbuser; password = dbpasswd; database =' - table --target -dir/path/to/hdfs/dir --split-by -m 1
从Microsoft网站下载连接器
http://www.microsoft.com/en-us/download/confirmation.aspx?id=11774
将它放在$ SQOOP_HOME/lib中
神谕
连接网址:
sqoop import --connect "jdbc:oracle:thin:@(description=(address=(protocol=tcp)(host=myhost)(port=1521))(connect_data=(service_name=myservice)))" \
--username USER --table SCHEMA.TABLE_NAME --hive-import --hive-table SCHEMA.TABLE_NAME \
--num-mappers 1 --verbose -P \
Run Code Online (Sandbox Code Playgroud)
IBM DB2
下载DB2Driver并将其放在$ SQOOP_HOME/lib中
sqoop import --driver com.ibm.db2.jcc.DB2Driver --connect jdbc:db2://db2.my.com:50000/testdb --username db2user --db2pwd --table db2tbl --split-by tbl_primarykey --target-dir sqoopimports
sqoop export --driver com.ibm.db2.jcc.DB2Driver --connect jdbc:db2://db2.my.com:50000/myDB --username db2user --password db2pwd --table db2tbl --export-dir /sqoop/dataFile.csv
Run Code Online (Sandbox Code Playgroud)
不同RDBMS的不同连接字符串
数据库版本 - 直接支持?连接字符串匹配
HSQLDB 1.8.0+没有jdbc:hsqldb:*//
MySQL 5.0+是的jdbc:mysql://
Oracle 10.2.0+没有jdbc:oracle:*//
PostgreSQL 8.3+是(仅导入)jdbc:postgresql://