案例分析:

  需要将hdfs上的数据导出到mysql里的一张表里。

  虚拟机集群的为:centos1-centos5

问题1:
在centos1上将hdfs上的数据导出到centos1上的mysql里:

sqoop export
  --connect jdbc:mysql://centos1:3306/test \
  --username root \
  --password root \
  --table order_uid \
  --export-dir /user/hive/warehouse/test.db/order_uid/ \
  --fields-terminated-by ','
报错:
Error executing statement: java.sql.SQLException: Access denied for user 'root'@'centos1' (using password: YES)

改成:

sqoop export 
  --connect jdbc:mysql://localhost:3306/test \
  --username root \
  --password root \
  --table order_uid \
  --export-dir /user/hive/warehouse/test.db/order_uid/ \
  --fields-terminated-by ','

报错:

Error: java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'test.order_uid' doesn't exist at
org.apache.sqoop.mapreduce.AsyncSqlRecordWriter.close(AsyncSqlRecordWriter.java:) at
org.apache.hadoop.mapred.MapTask$NewDirectOutputCollector.close(MapTask.java:) at
org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:) at org.apache.hadoop.mapred.MapTask.run(MapTask.java:) at
org.apache.hadoop.mapred.YarnChild$.run(YarnChild.java:) at java.security.AccessController.doPrivileged(Native Method) at
javax.security.auth.Subject.doAs(Subject.java:) at
...

问题2:

在centos3上将hdfs上的数据导出到centos1上的mysql里:

sqoop export
  --connect jdbc:mysql://centos1:3306/test \
  --username root \
  --password root \
  --table order_uid \
  --export-dir /user/hive/warehouse/test.db/order_uid/ \
  --fields-terminated-by ','

报错:

// :: ERROR mapreduce.ExportJobBase: Export job failed!
// :: ERROR tool.ExportTool: Error during export:
Export job failed!
at org.apache.sqoop.mapreduce.ExportJobBase.runExport(ExportJobBase.java:)
at org.apache.sqoop.manager.SqlManager.exportTable(SqlManager.java:)
at org.apache.sqoop.tool.ExportTool.exportTable(ExportTool.java:)
at org.apache.sqoop.tool.ExportTool.run(ExportTool.java:)
at org.apache.sqoop.Sqoop.run(Sqoop.java:)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:)
at org.apache.sqoop.Sqoop.runSqoop(Sqoop.java:)
at org.apache.sqoop.Sqoop.runTool(Sqoop.java:)
at org.apache.sqoop.Sqoop.runTool(Sqoop.java:)
at org.apache.sqoop.Sqoop.main(Sqoop.java:)

在网上找到两种解决方案:

1.在网上找到有人说在hdfs的路径写到具体文件,而不是写到目录,改成:

sqoop export
  --connect jdbc:mysql://centos1:3306/test \
  --username root \
  --password root \
  --table order_uid \
  --export-dir /user/hive/warehouse/test.db/order_uid/t1.dat \
  --fields-terminated-by ','

还是报相同错误!

2. 更改mysql里表的编码

将cengos1里mysql的表order_uid字符集编码改成:utf-8,重新执行,centos1的mysql表里导入了部分数据, 仍然报错:

Job failed as tasks failed. failedMaps: failedReduces:
// :: INFO mapreduce.Job: Counters:
File System Counters
FILE: Number of bytes read=
FILE: Number of bytes written=
FILE: Number of read operations=
FILE: Number of large read operations=
FILE: Number of write operations=
HDFS: Number of bytes read=
HDFS: Number of bytes written=
HDFS: Number of read operations=
HDFS: Number of large read operations=
HDFS: Number of write operations=
Job Counters
Failed map tasks=
Killed map tasks=
Launched map tasks=
Data-local map tasks=
Rack-local map tasks=
Total time spent by all maps in occupied slots (ms)=
Total time spent by all reduces in occupied slots (ms)=
Total time spent by all map tasks (ms)=
Total vcore-milliseconds taken by all map tasks=
Total megabyte-milliseconds taken by all map tasks=
Map-Reduce Framework
Map input records=
Map output records=
Input split bytes=
Spilled Records=
Failed Shuffles=
Merged Map outputs=
GC time elapsed (ms)=
CPU time spent (ms)=
Physical memory (bytes) snapshot=
Virtual memory (bytes) snapshot=
Total committed heap usage (bytes)=
File Input Format Counters
Bytes Read=
File Output Format Counters
Bytes Written=
// :: INFO mapreduce.ExportJobBase: Transferred 1.1035 KB in 223.4219 seconds (5.0577 bytes/sec)
// :: INFO mapreduce.ExportJobBase: Exported records.
// :: ERROR mapreduce.ExportJobBase: Export job failed!
// :: ERROR tool.ExportTool: Error during export:
Export job failed!
at org.apache.sqoop.mapreduce.ExportJobBase.runExport(ExportJobBase.java:)
at org.apache.sqoop.manager.SqlManager.exportTable(SqlManager.java:)
at org.apache.sqoop.tool.ExportTool.exportTable(ExportTool.java:)
at org.apache.sqoop.tool.ExportTool.run(ExportTool.java:)
at org.apache.sqoop.Sqoop.run(Sqoop.java:)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:)
at org.apache.sqoop.Sqoop.runSqoop(Sqoop.java:)
at org.apache.sqoop.Sqoop.runTool(Sqoop.java:)
at org.apache.sqoop.Sqoop.runTool(Sqoop.java:)
at org.apache.sqoop.Sqoop.main(Sqoop.java:)

当指定map为1时:

sqoop export
  --connect jdbc:mysql://centos1:3306/test \
  --username root \
  --password root \
  --table order_uid \
  --export-dir /user/hive/warehouse/test.db/order_uid \
  --fields-terminated-by ',' \
--m

运行成功了!!!

sqoop默认情况下的map数量为4,也就是说这种情况下1个map能运行成功,而多个map会失败。于是将map改为2又试了一遍:

sqoop export
  --connect jdbc:mysql://centos1:3306/test \
  --username root \
  --password root \
  --table order_uid \
  --export-dir /user/hive/warehouse/test.db/order_uid \
  --fields-terminated-by ',' \
--m 2

执行结果为:

// :: INFO mapreduce.Job: Counters:
File System Counters
FILE: Number of bytes read=
FILE: Number of bytes written=
FILE: Number of read operations=
FILE: Number of large read operations=
FILE: Number of write operations=
HDFS: Number of bytes read=
HDFS: Number of bytes written=
HDFS: Number of read operations=
HDFS: Number of large read operations=
HDFS: Number of write operations=
Job Counters
Failed map tasks=
Launched map tasks=
Data-local map tasks=
Rack-local map tasks=
Total time spent by all maps in occupied slots (ms)=
Total time spent by all reduces in occupied slots (ms)=
Total time spent by all map tasks (ms)=
Total vcore-milliseconds taken by all map tasks=
Total megabyte-milliseconds taken by all map tasks=
Map-Reduce Framework
Map input records=
Map output records=
Input split bytes=
Spilled Records=
Failed Shuffles=
Merged Map outputs=
GC time elapsed (ms)=
CPU time spent (ms)=
Physical memory (bytes) snapshot=
Virtual memory (bytes) snapshot=
Total committed heap usage (bytes)=
File Input Format Counters
Bytes Read=
File Output Format Counters
Bytes Written=
// :: INFO mapreduce.ExportJobBase: Transferred bytes in 99.4048 seconds (7.0922 bytes/sec)
// :: INFO mapreduce.ExportJobBase: Exported 5 records.
// :: ERROR mapreduce.ExportJobBase: Export job failed!
// :: ERROR tool.ExportTool: Error during export:
Export job failed!
at org.apache.sqoop.mapreduce.ExportJobBase.runExport(ExportJobBase.java:)
at org.apache.sqoop.manager.SqlManager.exportTable(SqlManager.java:)
at org.apache.sqoop.tool.ExportTool.exportTable(ExportTool.java:)
at org.apache.sqoop.tool.ExportTool.run(ExportTool.java:)
at org.apache.sqoop.Sqoop.run(Sqoop.java:)
at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:)
at org.apache.sqoop.Sqoop.runSqoop(Sqoop.java:)
at org.apache.sqoop.Sqoop.runTool(Sqoop.java:)
at org.apache.sqoop.Sqoop.runTool(Sqoop.java:)
at org.apache.sqoop.Sqoop.main(Sqoop.java:)

可以看到它成功的导入了5条记录!!!

通过jobhistory窗口可以看到两个map一个成功,一个执行失败

点击task的name:

成功的任务由centos4节点运行的,失败的task由centos1运行,又回到了问题1,就是centos1不能访问centos1的mysql数据!

最终一个朋友告诉我再centos1上单独添加对centos1的远程访问权限:

grant all privileges on *.* to 'root'@'centos1' identified by 'root' with grant option;
flush privileges;

然后重新运行一下,问题1和问题2都被愉快的解决了!!!

当时在centos1上的mysql里执行了:

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION; 
flush privileges;

对其他节点添加了远程访问,但没有对自己添加远程访问权限。

一个sqoop export案例中踩到的坑的更多相关文章

  1. 项目中踩过的坑之-sessionStorage

    总想写点什么,却不知道从何写起,那就从项目中踩过的坑开始吧,希望能给可能碰到相同问题的小伙伴一点帮助. 项目情景: 有一个id,要求通过当前网页打开一个新页面(不是当前页面),并把id传给打开的新页面 ...

  2. ng-zorro-antd中踩过的坑

    ng-zorro-antd中踩过的坑 前端项目中,我们经常会使用阿里开源的组件库:ant-design,其提供的组件已经足以满足多数的需求,拿来就能直接用,十分方便,当然了,有些公司会对组件库进行二次 ...

  3. 【spring】使用spring过程中踩到的坑

    这里简单记录一下,学习spring的时候碰过的异常: 异常:org.springframework.beans.factory.BeanDefinitionStoreException: Unexpe ...

  4. git工作中常用命令-工作中踩过的坑

    踩坑篇又来啦,这是我在工作中从git小白进化到现在工作中运用自如的过程中,踩过的坑,以及解决办法. 1.基于远程develop分支,建一个本地task分支,并切换到该task分支 git checko ...

  5. 转:Flutter开发中踩过的坑

    记录一下入手Flutter后实际开发中踩过的一些坑,这些坑希望后来者踩的越少越好.本文章默认读者已经掌握Flutter初步开发基础. 坑1问题:在debug模式下,App启动第一个页面会很慢,甚至是黑 ...

  6. vue项目开发中踩过的坑

    一.路由 这两天移动端的同事在研究vue,跟我说看着我的项目做的,子路由访问的时候是空白的,我第一反应是,不会模块没加载进来吧,还是....此处省略一千字... 废话不多说上代码 路由代码 { pat ...

  7. ionic2+angular2中踩的那些坑

    好久没写什么东西了,最近在做一个ionic2的小东西,遇到了不少问题,也记录一下,避免后来的同学走弯路. 之前写过一篇使用VS2015开发ionic1的文章,但自己还没摸清门道,本来也是感兴趣就学习了 ...

  8. JasperReport 中踩过的坑

      Mac Book Pro 10.13.6Jaspersoft Studio community version 6.6.9JDK 8 安装 Jaspersoft Studio Jasper Rep ...

  9. spring-data-redis 使用过程中踩过的坑

    spring-data-redis简介 Spring-data-redis是spring大家族的一部分,提供了在srping应用中通过简单的配置访问redis服务,对reids底层开发包(Jedis, ...

随机推荐

  1. Chapter 3 Top 10 List

    3.1 Introduction Given a set of (key-as-string, value-as-integer) pairs, then finding a Top-N ( wher ...

  2. Java 运算符(引用和对象)

    1. 算数运算符 就是+.-.*./.%.++.--这些,没什么好说的,稍微强调下自加,自减: 前缀自增自减法(++i,--i): 先进行自增或者自减运算,再进行表达式运算. 后缀自增自减法(i++, ...

  3. wooyun内网渗透教学分享之内网信息探测和后渗透准备

    常规的,从web业务撕开口子url:bit.tcl.comgetshell很简单,phpcms的,一个Phpcms V9 uc api SQL的老洞直接getshell,拿到shell,权限很高,sy ...

  4. 离散对数&&大步小步算法及扩展

    bsgs algorithm ax≡b(mod n) 大步小步算法,这个算法有一定的局限性,只有当gcd(a,m)=1时才可以用 原理 此处讨论n为素数的时候. ax≡b(mod n)(n为素数) 由 ...

  5. bootstrap清除浮动问题

    所有的col-样式都是左浮动 <div class="row">    <div class="col-xs-6 col-sm-3">d ...

  6. 8、Spring Cloud-配置中心 Spring Cloud Config(待补充)

    8.1.Config Server 本地读取配置文件 Config Server 可以从本地仓库读取配置文件,也可以从远处 Git 仓库读取.   本地仓库是指将所有的配置文件统 写在 Config ...

  7. 跳转到AppStore下载app

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://itunes.apple.com/cn/ap ...

  8. LORA芯片SX1272IMLTRT资料介绍

    升特公司(Semtech)(纳斯达克:SMTC)日前推出新型远程RFIC平台的首款产品SX1272,可将器件的无线传输距离扩大至15公里. 该器件集成了升特公司的新型LoRa(远程)调制技术,相比其他 ...

  9. PAT——1037. 在霍格沃茨找零钱

    如果你是哈利·波特迷,你会知道魔法世界有它自己的货币系统 —— 就如海格告诉哈利的:“十七个银西可(Sickle)兑一个加隆(Galleon),二十九个纳特(Knut)兑一个西可,很容易.”现在,给定 ...

  10. Shell笔记-02

    Shell支持自定义变量. 定义变量 定义变量时,变量名不加美元符号($),如: variableName="value" 注意,变量名和等号之间不能有空格,这可能和你熟悉的所有编 ...