Test MySQL Transaction management

Source: Internet
Author: User

Version 1.MySQL

Mysql> Selectversion ();+------------+|Version ()|+------------+| 5.5.Panax Notoginseng-Log |+------------+1Rowinch Set(0.00Sec

2. Create a test table

Mysql> Create TableTest_trans (IDint, name_varchar(Ten)); Query OK,0Rows Affected (0.29sec) MySQL>ShowTableStatus like 'test_trans%';+------------+--------+---------+------------+------+----------------+-------------+-|Name|Engine|Version|Row_format|Rows|Avg_row_length|Data_length|+------------+--------+---------+------------+------+----------------+-------------+-|Test_trans|InnoDB|      Ten |Compact|    0 |              0 |       16384 |+------------+--------+---------+------------+------+----------------+-------------+-1Rowinch Set(0.00Sec

3. Test things

MySQL supports local autocommit through set, START TRANSACTION, Commit, and rollback statements.
Transaction.
Grammar:
START TRANSACTION | BEGIN [Work]
COMMIT [Work] [and [No] CHAIN] [[No] RELEASE]
ROLLBACK [Work] [and [No] CHAIN] [[No] RELEASE]
SET autocommit = {0 | 1}

By default, MySQL is autocommit if it is necessary to commit and rollback by explicit commit and
Rolling back a transaction requires explicit transaction control commands to start the transaction, and Oracle's transaction management is obviously not
The same place. The start transaction or BEGIN statement can start a new transaction.
Commit and rollback are used to commit or rollback a transaction.

The start transaction or BEGIN statement can start a new transaction.
Commit and rollback are used to commit or rollback a transaction.
The chain and release clauses are used to define operations after a transaction commits or rolls back, and chain starts immediately
A new thing and has the same isolation level as the transaction just now, release disconnects the client from the connection

Mysql> begin     - Insert  intoTest_transValues(1,'segment'),(2,'tablespace'); ERROR1064(42000): You had an errorinchyour SQL syntax;CheckThe manual that corresponds toYour MySQL server version forThe RightSyntax to  UseNear'INSERT INTO Test_trans values (1,'Segment'), (2,'Tablespace')'At line2MySQL> Insert  intoTest_transValues(1,'segment'),(2,'tablespace'); Query OK,2Rows Affected (0.21sec) Records:2Duplicates:0Warnings:0MySQL> Select *  fromTest_trans;+------+------------+|Id|Name_|+------+------------+|    1 |Segment||    2 |Tablespace|+------+------------+2Rowsinch Set(0.00sec) MySQL> rollback; Query OK,0Rows Affected (0.00sec) MySQL> Select *  fromTest_trans;+------+------------+|Id|Name_|+------+------------+|    1 |Segment||    2 |Tablespace|+------+------------+2Rowsinch Set(0.00sec) A. No success, error, foundbeginThe statement is not written like this, then test MySQL> truncate TableTest_trans; Query OK,0Rows Affected (0.06sec) MySQL> begin ; Query OK,0Rows Affected (0.00sec) MySQL> Insert  intoTest_transValues(1,'segment'),(2,'tablespace'); Query OK,2Rows Affected (0.00sec) Records:2Duplicates:0Warnings:0MySQL> Select *  fromTest_trans;+------+------------+|Id|Name_|+------+------------+|    1 |Segment||    2 |Tablespace|+------+------------+2Rowsinch Set(0.00sec) MySQL> rollback; Query OK,0Rows Affected (0.08sec) MySQL> Select *  fromTest_trans; EmptySet(0.00sec) MySQL>B. Test the startTransactionMySQL>STARTTRANSACTION; Query OK,0Rows Affected (0.00sec) MySQL> Insert  intoTest_transValues(1,'segment'),(2,'tablespace'); Query OK,2Rows Affected (0.00sec) Records:2Duplicates:0Warnings:0MySQL> Select *  fromTest_trans;+------+------------+|Id|Name_|+------+------------+|    1 |Segment||    2 |Tablespace|+------+------------+2Rowsinch Set(0.00sec) MySQL> rollback; Query OK,0Rows Affected (0.07sec) MySQL> Select *  fromTest_trans; EmptySet(0.00sec) MySQL>

Test MySQL Transaction management

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.