<small id='l7KSn'></small><noframes id='l7KSn'>

        <bdo id='l7KSn'></bdo><ul id='l7KSn'></ul>
      <tfoot id='l7KSn'></tfoot>
    1. <legend id='l7KSn'><style id='l7KSn'><dir id='l7KSn'><q id='l7KSn'></q></dir></style></legend>

    2. <i id='l7KSn'><tr id='l7KSn'><dt id='l7KSn'><q id='l7KSn'><span id='l7KSn'><b id='l7KSn'><form id='l7KSn'><ins id='l7KSn'></ins><ul id='l7KSn'></ul><sub id='l7KSn'></sub></form><legend id='l7KSn'></legend><bdo id='l7KSn'><pre id='l7KSn'><center id='l7KSn'></center></pre></bdo></b><th id='l7KSn'></th></span></q></dt></tr></i><div id='l7KSn'><tfoot id='l7KSn'></tfoot><dl id='l7KSn'><fieldset id='l7KSn'></fieldset></dl></div>

        ALTER TABLE 不锁定表?

        ALTER TABLE without locking the table?(ALTER TABLE 不锁定表?)

        1. <tfoot id='2OmBq'></tfoot>
          <i id='2OmBq'><tr id='2OmBq'><dt id='2OmBq'><q id='2OmBq'><span id='2OmBq'><b id='2OmBq'><form id='2OmBq'><ins id='2OmBq'></ins><ul id='2OmBq'></ul><sub id='2OmBq'></sub></form><legend id='2OmBq'></legend><bdo id='2OmBq'><pre id='2OmBq'><center id='2OmBq'></center></pre></bdo></b><th id='2OmBq'></th></span></q></dt></tr></i><div id='2OmBq'><tfoot id='2OmBq'></tfoot><dl id='2OmBq'><fieldset id='2OmBq'></fieldset></dl></div>
            <bdo id='2OmBq'></bdo><ul id='2OmBq'></ul>
            <legend id='2OmBq'><style id='2OmBq'><dir id='2OmBq'><q id='2OmBq'></q></dir></style></legend>
              <tbody id='2OmBq'></tbody>

            <small id='2OmBq'></small><noframes id='2OmBq'>

                • 本文介绍了ALTER TABLE 不锁定表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 MySQL 中执行 ALTER TABLE 语句时,整个表在语句执行期间处于读锁定状态(允许并发读取,但禁止并发写入).如果它是一个大表,INSERT 或 UPDATE 语句可能会被阻塞很长时间.有没有办法进行热修改",比如添加一列,使表格在整个过程中仍然可以更新?

                  When doing an ALTER TABLE statement in MySQL, the whole table is read-locked (allowing concurrent reads, but prohibiting concurrent writes) for the duration of the statement. If it's a big table, INSERT or UPDATE statements could be blocked for a looooong time. Is there a way to do a "hot alter", like adding a column in such a way that the table is still updatable throughout the process?

                  我主要对 MySQL 的解决方案感兴趣,但如果 MySQL 无法做到,我会对其他 RDBMS 感兴趣.

                  Mostly I'm interested in a solution for MySQL but I'd be interested in other RDBMS if MySQL can't do it.

                  澄清一下,我的目的只是在将需要额外表列的新功能推送到生产时避免停机.任何数据库架构都会随着时间的推移而改变,这就是生活中的事实.我不明白为什么我们应该接受这些变化必然会导致停机;那只是弱.

                  To clarify, my purpose is simply to avoid downtime when a new feature that requires an extra table column is pushed to production. Any database schema will change over time, that's just a fact of life. I don't see why we should accept that these changes must inevitably result in downtime; that's just weak.

                  推荐答案

                  唯一的其他选择是手动完成许多 RDBMS 系统无论如何都会做的事情...
                  - 创建一个新表

                  The only other option is to do manually what many RDBMS systems do anyway...
                  - Create a new table

                  然后您可以一次将旧表的内容复制到一个块上.同时始终对源表上的任何 INSERT/UPDATE/DELETE 保持谨慎.(可以通过触发器管理.虽然这会导致减速,但它不是锁定...)

                  You can then copy the contents of the old table over a chunk at a time. Whilst always being cautious of any INSERT/UPDATE/DELETE on the source table. (Could be managed by a trigger. Although this would cause a slow down, it's not a lock...)

                  完成后,更改源表的名称,然后更改新表的名称.最好在交易中.

                  Once finished, change the name of the source table, then change the name of the new table. Preferably in a transaction.

                  完成后,重新编译使用该表的任何存储过程等.执行计划可能不再有效.

                  Once finished, recompile any stored procedures, etc that use that table. The execution plans will likely no longer be valid.

                  有些评论说这个限制有点差.所以我想我会对它提出一个新的观点来说明为什么它是这样的......

                  Some comments have been made about this limitation being a bit poor. So I thought I'd put a new perspective on it to show why it's how it is...

                  • 添加新字段就像更改每一行的一个字段.
                  • 字段锁比行锁更难,更不用说表锁了.

                  • 您实际上是在更改磁盘上的物理结构,每条记录都在移动.
                  • 这真的很像对整个表的更新,但影响更大......

                  这篇关于ALTER TABLE 不锁定表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)
                • <small id='fSYqQ'></small><noframes id='fSYqQ'>

                • <tfoot id='fSYqQ'></tfoot>
                  <i id='fSYqQ'><tr id='fSYqQ'><dt id='fSYqQ'><q id='fSYqQ'><span id='fSYqQ'><b id='fSYqQ'><form id='fSYqQ'><ins id='fSYqQ'></ins><ul id='fSYqQ'></ul><sub id='fSYqQ'></sub></form><legend id='fSYqQ'></legend><bdo id='fSYqQ'><pre id='fSYqQ'><center id='fSYqQ'></center></pre></bdo></b><th id='fSYqQ'></th></span></q></dt></tr></i><div id='fSYqQ'><tfoot id='fSYqQ'></tfoot><dl id='fSYqQ'><fieldset id='fSYqQ'></fieldset></dl></div>
                    <tbody id='fSYqQ'></tbody>

                        <bdo id='fSYqQ'></bdo><ul id='fSYqQ'></ul>

                        • <legend id='fSYqQ'><style id='fSYqQ'><dir id='fSYqQ'><q id='fSYqQ'></q></dir></style></legend>