Site updated: 2022-11-21 14:50:43
This commit is contained in:
5
atom.xml
5
atom.xml
@@ -21,8 +21,9 @@
|
||||
<id>https://blog.jingxiyuan.cn/2022/11/21/mysql%E6%95%B0%E6%8D%AE%E5%BA%93auto-increment%E8%87%AA%E5%A2%9E%E9%95%BF%E4%B8%8D%E5%8F%98%E7%9A%84%E5%A4%84%E7%90%86%E6%96%B9%E6%B3%95/</id>
|
||||
<title>mysql数据库auto_increment自增长不变的处理方法</title>
|
||||
<link rel="alternate" href="https://blog.jingxiyuan.cn/2022/11/21/mysql%E6%95%B0%E6%8D%AE%E5%BA%93auto-increment%E8%87%AA%E5%A2%9E%E9%95%BF%E4%B8%8D%E5%8F%98%E7%9A%84%E5%A4%84%E7%90%86%E6%96%B9%E6%B3%95/"/>
|
||||
<content type="html"><h4 id="引言"><a class="anchor" href="#引言">#</a> 引言</h4>
|
||||
<content type="html"><h4 id="问题描述"><a class="anchor" href="#问题描述">#</a> 问题描述</h4>
|
||||
<p>今天无意中发现原本能正常增加的 id 突然不变了,查看 sql 发现是取的对应表的自增 id。虽然存到表中的新数据自增 id 变化了,但返回的 id 总是不变。经过查询发现表的自增 id 是存在 information_schema 库中的 tables 表中。tables 表中存储了所有表的对应信息,其中有个 auto_increment 字段存储的就是对应表的下一个自增值。但是 mysql 在新版本中修改了此值的更新规则,老版本中是实时更新,新版本修改为 24 小时更新一次。为了不修改原代码中的逻辑,只能通过修改 mysql 配置使项目正常工作了。</p>
|
||||
<h4 id="解决办法"><a class="anchor" href="#解决办法">#</a> 解决办法</h4>
|
||||
<figure class="highlight yaml"><figcaption data-lang="YAML"></figcaption><table><tr><td data-num="1"></td><td><pre>mysql数据库auto_increment自增长不变的处理方法</pre></td></tr><tr><td data-num="2"></td><td><pre>修改/etc/mysql/mysql.conf.d/mysqld.cnf</pre></td></tr><tr><td data-num="3"></td><td><pre>增加一行information_schema_stats_expiry = 0</pre></td></tr><tr><td data-num="4"></td><td><pre>保存后重启mysql</pre></td></tr><tr><td data-num="5"></td><td><pre>sudo systemctl restart mysql.service</pre></td></tr><tr><td data-num="6"></td><td><pre></pre></td></tr><tr><td data-num="7"></td><td><pre>查询是否生效</pre></td></tr><tr><td data-num="8"></td><td><pre>show global variables like 'information_schema_stats_expiry';</pre></td></tr><tr><td data-num="9"></td><td><pre>show session variables like 'information_schema_stats_expiry';</pre></td></tr></table></figure></content>
|
||||
<category term="工作" scheme="https://blog.jingxiyuan.cn/categories/%E5%B7%A5%E4%BD%9C/" />
|
||||
<category term="解决问题" scheme="https://blog.jingxiyuan.cn/categories/%E5%B7%A5%E4%BD%9C/%E8%A7%A3%E5%86%B3%E9%97%AE%E9%A2%98/" />
|
||||
@@ -666,8 +667,8 @@ url 后缀必须用红线圈中的部分,key 在 chevereto 登陆后 api 配
|
||||
</content>
|
||||
<category term="Windows" scheme="https://blog.jingxiyuan.cn/categories/Windows/" />
|
||||
<category term="工具" scheme="https://blog.jingxiyuan.cn/categories/Windows/%E5%B7%A5%E5%85%B7/" />
|
||||
<category term="chevereto" scheme="https://blog.jingxiyuan.cn/tags/chevereto/" />
|
||||
<category term="PicGo" scheme="https://blog.jingxiyuan.cn/tags/PicGo/" />
|
||||
<category term="chevereto" scheme="https://blog.jingxiyuan.cn/tags/chevereto/" />
|
||||
<updated>2022-10-12T06:40:00.000Z</updated>
|
||||
</entry>
|
||||
<entry>
|
||||
|
||||
Reference in New Issue
Block a user