Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the characteristics of MySQL transaction

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what are the characteristics of MySQL transaction". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what are the characteristics of MySQL transaction".

What are the characteristics of MySQL transaction

Atomicity (atomicity) Consistency (stability, consistency) Isolation (isolation) Durability (reliability)

Note: transactions are valid only for statements that affect the data.

Showengines// looks at the data engines supported by mysql locks.

MyISAM does not support things, InnoDB supports things.

By default, MySQL will run in autocommit mode, which means that no small command will be executed as if there was only one command.

If you want mysql to support transactions, you only need to modify the data engine (altertablepersontype=INNODB).

Use the starttransaction or begin command to open a thing, and use commit, or rollback, to end it.

The end of things: things end not only with commit,rollback, but also with DDL or DCL statements.

Save point: through the save point mechanism: users can set some save points in things with the savepointname command. Later, when users use rollbacktosavepointname to end things, the data before name is saved, and the data after that is not saved.

Mysql uses keywords for transactions

Begin// opens a transaction. Commit// is submitted to the database. Rollback// cancels the operation. Savepoint// save, partially cancel, partially submit. Altertablepersontype=INNODB// modifies the data engine.

Example:

Beginupdatepersonsetname='efgh'whereid=10select*frompersonrollbackselect*fromperson

Example:

Altertablepersontype=INNODBbeginupdatepersonsetname='efgh'whereid=10select*frompersoncommitselect*frompersonbegindeletefrompersonwhereid=21updatepersonsetname='efgh'whereid=10commit/rollback

SavePoint must be used for the above partial submission.

What are the considerations for saving MySQL transactions?

1. Can only be canceled to a SavePoint rollbacktosavepointp1.

two。 Cannot submit some saved committosavepointp2// misspelling.

3. Finally, commit removes the uncanceled SavePoint from submitting to the data.

Examples of transaction SavePoint usage:

Begin;updatescoresetscore=40wherescoreid=1;savepoints1;updatescoresetscore=50wherescoreid=2;select*fromscore;rollbacktosavepoints1;select*fromscore;commit

Thank you for your reading, the above is the content of "what are the characteristics of MySQL transactions". After the study of this article, I believe you have a deeper understanding of what the characteristics of MySQL transactions are, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report