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

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

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

      1. <legend id='wVWDU'><style id='wVWDU'><dir id='wVWDU'><q id='wVWDU'></q></dir></style></legend>

        MySQL 并发,它是如何工作的,我是否需要在我的应用程序中处理它

        MySQL concurrency, how does it work and do I need to handle it in my application(MySQL 并发,它是如何工作的,我是否需要在我的应用程序中处理它)
        • <bdo id='to5tx'></bdo><ul id='to5tx'></ul>
          <tfoot id='to5tx'></tfoot>
          <i id='to5tx'><tr id='to5tx'><dt id='to5tx'><q id='to5tx'><span id='to5tx'><b id='to5tx'><form id='to5tx'><ins id='to5tx'></ins><ul id='to5tx'></ul><sub id='to5tx'></sub></form><legend id='to5tx'></legend><bdo id='to5tx'><pre id='to5tx'><center id='to5tx'></center></pre></bdo></b><th id='to5tx'></th></span></q></dt></tr></i><div id='to5tx'><tfoot id='to5tx'></tfoot><dl id='to5tx'><fieldset id='to5tx'></fieldset></dl></div>
          <legend id='to5tx'><style id='to5tx'><dir id='to5tx'><q id='to5tx'></q></dir></style></legend>

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

                  <tbody id='to5tx'></tbody>
                  本文介绍了MySQL 并发,它是如何工作的,我是否需要在我的应用程序中处理它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我目前正在运行一个 MySQL 数据库.我所有的表都使用表引擎 InnoDB.

                  I am currently running a MySQL database. All of my tables are using the Table Engine InnoDB.

                  登录我的应用程序的每个人都可以查看记录,我担心在某些时候两个用户可能会同时更新或插入记录.MySQL 是否优雅地处理了这种类型的并发问题,还是我必须将其编程到我的代码中?

                  Everyone who logs into my application can view records and I am worried that at some point two users might update or insert a record at the same time. Does MySQL handle this type of concurrency issue gracefully, or is this something that I am going to have to program into my code?

                  如果我必须将它编程到我的代码中,您将如何处理这样的并发情况?

                  If I do have to program it into my code how do you go about handling a concurrency case like this?

                  推荐答案

                  SQL 语句是原子的.也就是说,如果你执行这样的事情:

                  SQL statements are atomic. That is, if you execute something like this:

                  UPDATE Cars SET Sold = Sold + 1
                  

                  在此声明期间,没有人可以更改 Sold 变量.它总是加 1,即使其他人正在同时执行相同的语句.

                  Nobody can change the Sold variable during this statement. It is always incremented by 1, even if somebody else is executing the same statement concurrently.

                  如果你有相互依赖的语句,就会出现问题:

                  The problem occurs if you have statements that depend on each other:

                  a = SELECT Sold FROM Cars;
                  UPDATE Cars SET Sold = a + 1;
                  

                  在这些查询之间,另一个用户可以更改表 Cars 并更新 Sold.为了防止这种情况,请将其包装在一个事务中:

                  Between these queries, another user can change the table Cars and update Sold. To prevent this, wrap it in a transaction:

                  BEGIN;
                  a = SELECT Sold FROM Cars;
                  UPDATE Cars SET Sold = a + 1;
                  COMMIT;
                  

                  InnoDB 支持事务,但 MyISAM 不支持.

                  Transactions are supported by InnoDB, but not by MyISAM.

                  这篇关于MySQL 并发,它是如何工作的,我是否需要在我的应用程序中处理它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  How to delete duplicate records in mysql database?(如何删除mysql数据库中的重复记录?)
                  Python Pandas write to sql with NaN values(Python Pandas 使用 NaN 值写入 sql)
                  MySQL Insert amp; Joins(MySQL 插入 amp;加入)
                  MySQL concat() to create column names to be used in a query?(MySQL concat() 创建要在查询中使用的列名?)
                  NodeJS responded MySQL timezone is different when I fetch directly from MySQL(当我直接从 MySQL 获取时,NodeJS 响应 MySQL 时区不同)
                  WHERE datetime older than some time (eg. 15 minutes)(WHERE 日期时间早于某个时间(例如 15 分钟))

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

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