1.hive-table

从mysql导入数据到hive表中,可以使用--hive-table来指定hive的表名,不指定hive表名,则hive表名与mysql表名保持一致。

  1. sqoop import --connect jdbc:mysql://localhost:3306/test --username root --password 123456 --table person --hive-import --fields-terminated-by '|' --lines-terminated-by "\n" -m 1 --hive-table person_mysql

hive中的表结构是:

  1. hive> show create table person_mysql;
  2. OK
  3. CREATE TABLE `person_mysql`(
  4. `id` int,
  5. `name` string)
  6. COMMENT 'Imported by sqoop on 2016/07/26 15:13:48'
  7. ROW FORMAT DELIMITED
  8. FIELDS TERMINATED BY '|'
  9. LINES TERMINATED BY '\n'
  10. STORED AS INPUTFORMAT
  11. 'org.apache.hadoop.mapred.TextInputFormat'
  12. OUTPUTFORMAT
  13. 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
  14. LOCATION
  15. 'hdfs://hadoop26:8020/user/hive/warehouse/person_mysql'
  16. TBLPROPERTIES (
  17. 'COLUMN_STATS_ACCURATE'='true',
  18. 'numFiles'='',
  19. 'totalSize'='',
  20. 'transient_lastDdlTime'='')
  21. Time taken: 0.21 seconds, Fetched: row(s)

2.create-hive-table工具

create-hive-table工具是依据mysql中的表定义在hive中创建一个表

  1. sqoop create-hive-table --connect jdbc:mysql://localhost:3306/test --username root --password 123456 --table person --hive-table person_mysql_222 fields-terminated-by '|'

只在hive中创建了表,没有把数据进行导入,所以hive表中是没有数据的:

  1. hive> select * from person_mysql_222;
  2. OK
  3. Time taken: 0.299 seconds
  4. hive> show create table person_mysql_222;
  5. OK
  6. CREATE TABLE `person_mysql_222`(
  7. `id` int,
  8. `name` string)
  9. COMMENT 'Imported by sqoop on 2016/07/26 15:22:14'
  10. ROW FORMAT DELIMITED
  11. FIELDS TERMINATED BY '|'
  12. LINES TERMINATED BY '\n'
  13. STORED AS INPUTFORMAT
  14. 'org.apache.hadoop.mapred.TextInputFormat'
  15. OUTPUTFORMAT
  16. 'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
  17. LOCATION
  18. 'hdfs://hadoop26:8020/user/hive/warehouse/person_mysql_222'
  19. TBLPROPERTIES (
  20. 'transient_lastDdlTime'='')
  21. Time taken: 0.22 seconds, Fetched: row(s)

3.import-all-tables工具

将数据库中所有的表都导入到hive中

目前mysql中有person、sun两张表

  1. sqoop import-all-tables --connect jdbc:mysql://localhost:3306/test --username root --password 123456 --hive-import -m 1

这样在hive中也生成了两张表,分别是person和sun.

在这个语句中也可以指定hive-table来指定一个表名,这样多个表的数据就会导入到一个hive表中了。

  1. sqoop import-all-tables --connect jdbc:mysql://localhost:3306/test --username root --password 123456 -m 1 --hive-import --hive-table all_person

sqoop导入数据到hive---2的更多相关文章

  1. sqoop导入数据到hive

    1.1hive-import参数 使用--hive-import就可以将数据导入到hive中,但是下面这个命令执行后会报错,报错信息如下: sqoop import --connect jdbc:my ...

  2. sqoop导入数据到hive中元数据问题

    简单配置了sqoop之后开始使用,之前用的时候很好用,也不记得有没有启动hivemetastore,今天用的时候没有启动,结果导入数据时,如果使用了db.tablename,就会出现找不到数据库的错, ...

  3. sqoop导入数据到hive表中的相关操作

    1.使用sqoop创建表并且指定对应的hive表中的字段的数据类型,同时指定该表的分区字段名称 sqoop create-hive-table --connect "jdbc:oracle: ...

  4. 使用Sqoop从MySQL导入数据到Hive和HBase 及近期感悟

    使用Sqoop从MySQL导入数据到Hive和HBase 及近期感悟 Sqoop 大数据 Hive HBase ETL 使用Sqoop从MySQL导入数据到Hive和HBase 及近期感悟 基础环境 ...

  5. 使用sqoop从mysql导入数据到hive

      目录 前言 一.使用的导入命令 二.遇到的问题及解决 1. 用文本字段进行分区的问题 2. Hadoop历史服务器Hadoop JobHistory没开启的问题 3. 连接元数据存储数据库报错 4 ...

  6. 教程 | 使用Sqoop从MySQL导入数据到Hive和HBase

    基础环境 sqoop:sqoop-1.4.5+cdh5.3.6+78, hive:hive-0.13.1+cdh5.3.6+397, hbase:hbase-0.98.6+cdh5.3.6+115 S ...

  7. Sqoop导入关系数据库到Hive

    参考:segmentfault.com:Sqoop导入关系数据库到Hive Sqoop 是 apache 下用于 RDBMS 和 HDFS 互相导数据的工具.本文以 mysql 数据库为例,实现关系数 ...

  8. 使用sqoop1.4.4从oracle导入数据到hive中错误记录及解决方案

    在使用命令导数据过程中,出现如下错误 sqoop import --hive-import --connect jdbc:oracle:thin:@192.168.29.16:1521/testdb ...

  9. Sqoop导入数据到mysql数据库报错:ERROR tool.ExportTool: Error during export: Export job failed!(已解决)

    问题描述: Container killed by the ApplicationMaster. Container killed on request. Exit code is 143 Conta ...

随机推荐

  1. HOST ip is not allowed to connect to this MySql server

    报错:1130-host ... is not allowed to connect to this MySql server 解决方法: 1. 改表法. 可能是你的帐号不允许从远程登陆,只能在loc ...

  2. nyoj 56-阶乘因式分解(一)

    点击打开链接 阶乘因式分解(一) 时间限制:3000 ms  |  内存限制:65535 KB 难度:2 描述 给定两个数m,n,其中m是一个素数. 将n(0<=n<=10000)的阶乘分 ...

  3. Contains DuplicateII

    超时版: /*Contains Duplicate II Given an array of integers and an integer k, find out whether there the ...

  4. oracle分布式事务总结-转载

    基本概念 Local Coordinator:在分布事务中,必须参考其它节点上的数据才能完成自己这部分操作的站点. Global Coordinator:分布事务的发起者,负责协调这个分布事务. Co ...

  5. openssl rsa 私钥 PKCS8私钥 公钥

    上文配置好 openssl 运行 => cmd => cd C:\usr\local\ssl\bin => 执行 openssl

  6. fw: firefox plugin

    http://blog.csdn.net/fancycow/article/details/7261191 firefox的插件分两种类型,一种extension,叫扩展,一种是plugin,我们叫插 ...

  7. android 操作sqlite的一点小技巧

    1.android 在sqlite插入数据时,是非常耗时的操作,原因是sqlite缺省会为每个插入操作开启一个事务,当数量变多的时候,自然时间就变得很慢,这时候可以考虑在插入等操作时先开启一个事务,再 ...

  8. flex使用buttonbar为viewstack添加导航功能

    先建立一个Main.mxml的应用程序,作为一个主程序,再建立两个component ,一个是jiaju.mxml ,另一个是dianqi.mxml. Main.mxml:  <?xml ver ...

  9. Exercises - Kangaroo

    Write a definition for a class named Kangaroo with the following methods: An __init__ method that in ...

  10. 处理程序“WebServiceHandlerFactory-Integrated”在其模块列表中有一个错误模块“ManagedPipelineHandler”

    开发web项目时需要安装IIS,在安装好IIS的Windows7本上发布asp.net网站时,web程序已经映射到了本地IIS上,但运行如下错误提示“处理程序“PageHandlerFactory-I ...