防止 MYSQL 在服务器重启时重置自动增量值 [英] prevent MYSQL from resetting Auto increment values on Server restart

查看:78
本文介绍了防止 MYSQL 在服务器重启时重置自动增量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们遇到了情况.我们使用自动增量存储 id 并删除行以保持表清洁.我们不希望 MYSQL 在意外重启时重置自动增量.虽然在删除 MYSQL 时不会重置 auto inc 计数器,我们对此感到满意,但偶尔 MYSQL 会重新启动,并且该计数器会重置为 max(id) +1.我们想避免这种情况,有没有办法告诉 MYSQL 将自动递增计数器保持在重启前的位置.

We have a situation. We store id with auto increment and delete the rows to keep table clean. We do not want MYSQL to reset the auto increment when it gets rebooted accidentally. Though upon deleting MYSQL do not reset the auto inc counter and we are happy with that but occasionally MYSQL restart and that counter is reset to max(id) +1. We want to avoid that, is there a way we can tell MYSQL to keep the auto increment counter to where it was before the restart.

推荐答案

It's know bug: https://bugs.mysql.com/bug.php?id=199.该错误尚未解决.

It's know bug: https://bugs.mysql.com/bug.php?id=199. The bug is not solved yet.

最好的解决方法可能是使用序列:https://openquery.com.au/blog/implementing-sequences-using-a-stored-function-and-triggers

The best workaround probably is to use sequences: https://openquery.com.au/blog/implementing-sequences-using-a-stored-function-and-triggers

这篇关于防止 MYSQL 在服务器重启时重置自动增量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆