MySQLIntegrityConstraintViolationException: Duplicate entry '47504266' for key 'PRIMARY'
来源:互联网 发布:香港警匪片推荐知乎 编辑:程序博客网 时间:2024/06/08 16:31
一般都知道,Duplicate entry xxxx for key 'PRIMARY' 是主键重复,但是还有一种情况一定要注意;
那就是创建一个表的时候一定要注意索引名称,不能和其他表的索引名称相同(尤其是主键名称);而且一旦出现这个问题,比较难发现;
事件回顾:
早上监控系统时发现我有一个任务卡住了,我第一反应是线程卡死了,因为之前有遇到过,但我重启了应用服务没有解决问题,所以我再去看错误日志,发现了如下异常栈信息,因此,我找到对应的表,执行查询命令 select * from t_xxx where id = 47504266; 咦!? 发现并没有这条数据,这是啥原因,难道mysql自增ID有BUG? 难道jdbc驱动有BUG? 头脑里闪现出多个可能性,但是我仔细一想,肯定都不是这些问题,我把现在的表重命名重新再建试一试? 哎呀!我的晕啊,一看原来的DDL语句,索引名用的是上月表名的索引,难怪出问题了。
解决: 果断调整重建表,修正索引名称,重启应用服务,终于正常了!但是,这也是一个生产事故,因为重建了表,对应的数据需要作处理,这将带来至少一天的业务需要监控和维护,需要对数据进行一些处理,这是很麻烦的一件事情。因此,在创建月表的时候不能偷懒,要写好shell脚本,尽量不要手工创建。
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '47504266' for key 'PRIMARY'
at sun.reflect.GeneratedConstructorAccessor60.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1040)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4006)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2468)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2629)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2719)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1379)
at com.jolbox.bonecp.PreparedStatementHandle.execute(PreparedStatementHandle.java:140)
at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:44)
at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:69)
at sun.reflect.GeneratedMethodAccessor38.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:62)
at com.sun.proxy.$Proxy173.update(Unknown Source)
at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:48)
at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:105)
at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:152)
at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:141)
at sun.reflect.GeneratedMethodAccessor43.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:497)
at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
... 29 more
0 0
- MySQLIntegrityConstraintViolationException: Duplicate entry '47504266' for key 'PRIMARY'
- MySQLIntegrityConstraintViolationException: Duplicate entry '***' for key 'PRIMARY'
- Duplicate entry '##' for key 'PRIMARY'
- Duplicate entry '5' for key 'PRIMARY'
- Duplicate entry '0' for key 'PRIMARY'.
- Duplicate entry '20120323' for key 'PRIMARY'
- Duplicate entry '222' for key 'PRIMARY'
- Duplicate entry 't_id' for key 'PRIMARY' 错误
- Duplicate entry '0' for key 'PRIMARY'.
- Duplicate entry '125152' for key 'PRIMARY'
- 关于“Duplicate entry '1403070003' for key 'PRIMARY'”
- Duplicate entry '1' for key 'PRIMARY'
- Duplicate entry '127' for key 'PRIMARY'
- Duplicate entry '0' for key 'PRIMARY'错误
- Duplicate entry '0' for key 'PRIMARY'
- Duplicate entry '1-9' for key 'PRIMARY'
- Duplicate entry for key 'PRIMARY' 的问题
- Duplicate entry '0' for key 'PRIMARY'
- 抽奖算法 - 幸运大转盘 - java
- C# winform 开发注意事项
- 利用JS对两行Input radio 进行互斥选择。
- poj 2195 Going Home(二分图最优匹配KM算法)
- 勾股定理一日一证连载115
- MySQLIntegrityConstraintViolationException: Duplicate entry '47504266' for key 'PRIMARY'
- js简单的dom操作
- 源码-JavaScript&jQuery交互式前端开发-第3章-函数、方法与对象-使用构造函数语法创建对象
- The First Step
- 设计的第二个程序
- 函数指针
- CUDA 中 FFT 的使用
- tcp/ip协议的三次握手
- ArcGIS Server数据注册