关于sqoop导出数据到mysql关系型数据库当中报错的解决( java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '65199357' for key 'PRIMARY')

最近在做将将hive当中的数据导出到mysql的关系型数据库当中,然后在mysql的关系型数据库当中建了主键,然后将数据导出到数据就报错,最后查看在hive导出数据到关系型数据库的过程当中如果有重复的字段值就会出现下面的问题:

2018-09-10 09:34:44,710 FATAL [IPC Server handler 2 on 58094] org.apache.hadoop.mapred.TaskAttemptListenerImpl: Task: attempt_1536298905044_0087_m_000001_0 - exited : java.io.IOException: Can't export data, please check failed map task logs
    at org.apache.sqoop.mapreduce.TextExportMapper.map(TextExportMapper.java:122)
    at org.apache.sqoop.mapreduce.TextExportMapper.map(TextExportMapper.java:39)
    at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:145)
    at org.apache.sqoop.mapreduce.AutoProgressMapper.run(AutoProgressMapper.java:64)
    at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:793)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
    at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:164)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:415)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1917)
    at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)
Caused by: java.io.IOException: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '65199357' for key 'PRIMARY'
    at org.apache.sqoop.mapreduce.AsyncSqlRecordWriter.write(AsyncSqlRecordWriter.java:233)
    at org.apache.sqoop.mapreduce.AsyncSqlRecordWriter.write(AsyncSqlRecordWriter.java:46)
    at org.apache.hadoop.mapred.MapTask$NewDirectOutputCollector.write(MapTask.java:664)
    at org.apache.hadoop.mapreduce.task.TaskInputOutputContextImpl.write(TaskInputOutputContextImpl.java:89)
    at org.apache.hadoop.mapreduce.lib.map.WrappedMapper$Context.write(WrappedMapper.java:112)
    at org.apache.sqoop.mapreduce.TextExportMapper.map(TextExportMapper.java:90)
    ... 10 more


这个错一看就很明显就是字段的值重复了,然后造成数据不能写入到关系型数据库当中导致的。所以我们在建表的时候一定要注意主键是否是重复的一旦重复数据是绝对导入不进去的。

 

posted on 2018-09-10 10:40  gxg123  阅读(1801)  评论(0编辑  收藏  举报

导航