dougou6727 2015-03-03 15:32
浏览 49

恢复转储后,MySQL InnoDB AUTO_INCREMENT失败

I have database with InnoDB tables in a production server and development. Several tables have auto_increment columns and there are few Foreign Keys also included.

Problem is that after taking a dump (schema and data) from production to development server, suddenly NO new insert from PHP increases any auto_increment key and they result having ai_key 0 in the table. I thought this should even not be possible without touching sql_mode setting on server. After this 0-key, all procedures just updates the 0-key row on database.

Insert goes like this (just for example):

IF vCol = 0 AND (SELECT COUNT(*) FROM aTable WHERE `aId` = vId) = 0     
THEN
    INSERT INTO aTable (
        `aId`,
        `bRandomCol`
    )
    VALUES
    (
        vCol,
        vRandomCol
    )

Using mysqli and prepared statements in PHP.

Calling prosedure outside PHP also fails. Making pure insert clause including auto_increment field into it and giving value 0 for it, that succeeds.

Inspecting table with SHOW TABLE STATUS FROM X LIKE 'Y' results the correct key in order.

I can repair the problem with ALTER TABLE X AUTO_INCREMENT = Z.

Have anyone seen problem like this before or know why this happens or is there any workaround?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
    • ¥15 关于#Java#的问题,如何解决?