MySQL parameters of the autocommit of the detailed

Source: Internet
Author: User
Tags commit rollback mysql database


Autocommit is a change in transaction submission method parameters, set to 1 o'clock, all changes to the immediate effect of the change, that is, 1 o'clock, after the execution of the statement, the transaction automatically submitted. If set to 0 o'clock, commit or ROLLBACK transaction is required through commit or rollback. To correct one argument is that set autocommit = 0 o'clock, will automatically open a transaction, exactly set autocommit = 0 o'clock the Next statement automatically opens a transaction. Set autocommit = 0 differs from start transaction: The former changes the transaction submission method, is autocommit or not autocommit, the setting does not cause the preceding transaction to be implicitly submitted; the latter is to open a transaction immediately and implicitly submit the preceding transaction

Set autocommit = 1 The difference between a commit can be submitted to the previous transaction, but in 5.0, 5.1 of the version will be different, specific to see the bug#54462

Another important point to note: Python uses mysqldb to connect to the MySQL database, autocommit default will be set to OFF, each SQL comes in, you need to commit to commit the transaction. The code is set to ON, and if a transaction is required, it is opened by the start transaction method.

As an example:

John Transfer 500 yuan to dick. Then the following actions should be in the database:

1, check the John account balance is sufficient
2, John's account minus 500 yuan.
3, Dick's account plus 500 dollars.

The above three steps can be placed in a transaction to execute the commit, either full or none, if all OK commits to commit permanent change data, or rollback rollback to the state before the change if an error occurs. The use of transactions will not appear John money less Dick account but did not add 500 yuan or John the money did not subtract Dick account but added 500 yuan.

MySQL's default storage engine is that the Myisam,myisam storage engine does not support transactions, so changing autocommit has little effect. But there is no error, so the child shoes to use the transaction must determine what you are doing to support transaction processing, such as InnoDB. If you do not know the storage engine for a table can specify the transaction type's storage engine by viewing the build table, and if you do not specify the storage engine by default, the MyISAM does not support transactions.
Of course, transactions are designed to ensure the atomicity, consistency, isolation, and durability of table data. These are to consume system resources, to choose carefully.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.