如何使用sqoop将数据从关系数据库导入沙盒配置单元?

elcex8rz  于 2021-06-04  发布在  Hadoop
关注(0)|答案(2)|浏览(278)

如何使用sqoop将数据从关系数据库导入沙盒中的配置单元。我已经安装了霍顿工程沙盒在我的电脑。我想知道这个迁移。我已经参考了这个链接http://hortonworks.com/kb/using-apache-sqoop-for-data-import-from-relational-dbs/ 但我有点疑惑1,它需要任何sqoop软件来运行吗?2、在上面标注的链接中有一些代码我会把这个代码放在哪里?在配置单元查询窗口中?3、是否可以完全(或仅在一个时间表上)迁移数据库?4、存储过程和viwe呢?我将把这些都放在哪里?

6pp0gazn

6pp0gazn1#

1-您需要microsoft sql server connector for apache hadoop来完成此任务,可从此处下载。
2-必须从sqoop shell发出import命令。我建议您浏览一下sqoop文档,特别是第7.2.10节,它告诉我们如何将数据导入到hive中。
3-你可以:
使用import all tables从数据库导入所有表
使用sqoop import导入一个表
分别使用,-where或--columns参数导入表的一部分(特定行或特定列)
使用sqoop export将数据从hdfs导出到关系数据库。
4-一旦数据进入hadoop集群,就不能再使用sql过程了。存储过程语言通常对结果集执行更多的逻辑操作。由于配置单元结果集通常很大,因此聚合和转换要么使用函数要么使用流式处理。您需要考虑一些替代方法。但是你可以在Hive里看到。要在Hive中查找更多视图,请访问此处。
hth公司

c6ubokkw

c6ubokkw2#

sqoop预装了最新的horton沙盒。你必须做以下事情。如果出现某些情况,您可能需要权限(不允许主机“.xx..”连接到此mysql服务器)。否则请执行以下操作-将数据从rdbms(mysql、oracle等)导入和导出到hdfs/hive/hbase
先决条件
apache hadoop
apache sqoop(与hadoop版本兼容)
apache配置单元(可选)
apache hbase(可选)
apache hcatalog(可选)
jdbc/odbc连接器
对于所有rdbms,连接url都会更改,其余所有命令行参数保持不变。您需要下载特定的jdbc/odbc连接器jar并将其复制到$sqoop\u home/lib
mysql数据库
下载mysql-connector-java.jar并放入$sqoop\u 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

mysql到hdfs导入
具有主键:

sqoop import -connect jdbc:mysql://localhost:3306/db1 -username root -password password --table tableName --target-dir /path/to/directoryName

无主键:

sqoop import -connect jdbc:mysql://localhost:3306/db1 -username root -password password --table tableName --target-dir /path/to/directoryName  -m 1

mysql到配置单元导入
具有主键:

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

无主键:

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

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

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

要使用主键创建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

要使用没有主键的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

从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'

sql服务器
连接url:
sqoop导入--connect'jdbc:sqlserver://;用户名=dbuser;密码=dbpasswd;database='--表--目标目录/path/to/hdfs/dir--按-m1拆分
从microsoft网站下载连接器
http://www.microsoft.com/en-us/download/confirmation.aspx?id=11774
把它放在$sqoop\u home/lib中
Oracle
连接url:

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 \

ibm db2公司
下载db2driver并将其放在$sqoop\u 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

不同rdbms的不同连接字符串
数据库版本--直接支持?连接字符串匹配项
hsqldb 1.8.0+否jdbc:hsqldb://
MySQL5.0+是jdbc:mysql://
oracle 10.2.0+否jdbc:oracle:
//
postgresql 8.3+是(仅限导入)jdbc:postgresql://

相关问题