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

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

  1. <legend id='x4yZG'><style id='x4yZG'><dir id='x4yZG'><q id='x4yZG'></q></dir></style></legend>
  2. <tfoot id='x4yZG'></tfoot>
    1. Mysql 事务:提交和回滚

      时间:2023-10-10
      1. <tfoot id='Zl8YZ'></tfoot>
        • <small id='Zl8YZ'></small><noframes id='Zl8YZ'>

            <bdo id='Zl8YZ'></bdo><ul id='Zl8YZ'></ul>
              <tbody id='Zl8YZ'></tbody>

          • <legend id='Zl8YZ'><style id='Zl8YZ'><dir id='Zl8YZ'><q id='Zl8YZ'></q></dir></style></legend>
            • <i id='Zl8YZ'><tr id='Zl8YZ'><dt id='Zl8YZ'><q id='Zl8YZ'><span id='Zl8YZ'><b id='Zl8YZ'><form id='Zl8YZ'><ins id='Zl8YZ'></ins><ul id='Zl8YZ'></ul><sub id='Zl8YZ'></sub></form><legend id='Zl8YZ'></legend><bdo id='Zl8YZ'><pre id='Zl8YZ'><center id='Zl8YZ'></center></pre></bdo></b><th id='Zl8YZ'></th></span></q></dt></tr></i><div id='Zl8YZ'><tfoot id='Zl8YZ'></tfoot><dl id='Zl8YZ'><fieldset id='Zl8YZ'></fieldset></dl></div>
                本文介绍了Mysql 事务:提交和回滚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我将我的 PhpMyAdmin 数据库引擎从 MyISAM 更新到 INNODB 以允许回滚.

                I updated my PhpMyAdmin database engine from MyISAM to INNODB to allow rollback.

                这是我的 SQL 查询:

                This is my SQL query :

                START TRANSACTION;
                UPDATE jkm_content SET state=0 WHERE title IN ('title-1','title2');
                

                结果:

                start transaction;# MySQL returned an empty result set (i.e. zero
                rows).
                UPDATE jkm_content SET state=1 WHERE title IN ('title-1','title2');# 2 rows affected.
                

                1) 所以语句告诉我有 2 行受到影响,但更改没有出现在任何地方(既不在我的数据库中也不在网站中).我虽然 start transaction 可以让我形象化更改(在临时数据库中),然后如果我满意,我会提交"查询.(我知道我需要 commit 来更新数据库,但如果我 commit 更改将是永久性的).

                1) So the statement informs me that 2 rows are affected but the change doesn't appear anywhere (neither in my DB nor in the website).I though start transaction would allow me to visualize the changes (in a temporary DB) and then if I am satisfy I "commit" the query. (I understand I need to commit to update the DB, but if I commit the change will be permanent).

                2) 那么如果我在提交之前看不到效果,我就不明白 rollback 的意义.这两个查询之间有什么区别:

                2) Then I don't get the point of rollbackif I can't see the effect before committing it. What will be the difference between these two queries :

                START TRANSACTION;
                UPDATE jkm_content SET state=0 WHERE title IN ('title-1','title2');
                

                START TRANSACTION;
                UPDATE jkm_content SET state=0 WHERE title IN ('title-1','title2');
                ROLLBACK;
                

                3) 如果我猜对了,这些功能都是一样的 :

                3) if I got it right, these functions are all the same :

                START TRANSACTION
                BEGIN
                BEGIN WORK
                

                推荐答案

                1) 您所做的所有更改都在同一事务中可见.如果你这样做

                1) All changes you make are visible within the same transaction. If you do

                START TRANSACTION;
                INSERT INTO MyTable VALUES ('Hi there');
                SELECT * FROM MyTable;
                

                您的输出将包括您好".但是,如果您启动第二个数据库连接,则在您从第一个连接中提交事务之前,不会显示新行.尝试使用命令行使用两个数据库连接来玩这个.

                your output will include the 'Hi there'. But if you start a second database-connection the new row won't be displayed until you commit your transaction from within the first connection. Try playing with this using two database-connections using the command-line.

                您没有在您的网站中看到效果,因为您不能在两个数据库连接中进行相同的事务(将在您的请求开始时创建一个新的数据库连接).

                You're not seeing the effect in your website because you can't have the same transaction within two database-connection (a new db-connection will be made at the beginning of your request).

                2) 当与数据库的连接关闭时,所有未提交的事务将回滚.因此,如果这是您仅有的两个查询,则没有区别.但是有区别

                2) All transactions that aren't committed will be rolled back when the connection with the database is closed. So if these are your only two queries, there are no difference. However there is a difference between

                START TRANSACTION;
                INSERT INTO MyTable VALUES ('This one would be discarded on rollback');
                ROLLBACK;
                INSERT INTO MyTable VALUES ('This one will be permanent because not within transaction');  
                

                3) 是的,这些都是一样的.

                3) Yes, these are all the same.

                这篇关于Mysql 事务:提交和回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:在 php 中获取 DATETIME 并将其发布到 MySQL 以保持事务一致性 下一篇:多个服务层和数据库事务

                相关文章

              1. <small id='Vk0bI'></small><noframes id='Vk0bI'>

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

                    <legend id='Vk0bI'><style id='Vk0bI'><dir id='Vk0bI'><q id='Vk0bI'></q></dir></style></legend>

                    • <bdo id='Vk0bI'></bdo><ul id='Vk0bI'></ul>