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