mysql的默认的隔离级别是可重复读,oracle的默认的隔离级别是读提交,下面是mysql的隔离级别的测试:

查看mysql的事务隔离级别

SELECT @@global.tx_isolation; 
SELECT @@session.tx_isolation; 
SELECT @@tx_isolation;
修改事务隔离级别

set tx_isolation='read-committed';

mysql> set autocommit=off;
Query OK, 0 rows affected (0.00 sec)


mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)


mysql> select * from event;
+--------+------------------+----+
| name   | value            | id |
+--------+------------------+----+
| nba    | i love this game |  1 |
| it     | baidu            |  2 |
| spring | spring in action |  3 |
| nba    | i am back        |  4 |
+--------+------------------+----+
4 rows in set (0.00 sec)

point A:


mysql> select * from event;
+--------+------------------+----+
| name   | value            | id |
+--------+------------------+----+
| nba    | i love this game |  1 |
| it     | baidu            |  2 |
| spring | spring in action |  3 |
| nba    | i am back        |  4 |
+--------+------------------+----+
4 rows in set (0.00 sec)

在point A的时刻,在另一个窗口执行下面的命令:

mysql> set autocommit=off;
Query OK, 0 rows affected (0.00 sec)


mysql> start transaction;
Query OK, 0 rows affected (0.00 sec)


mysql> select * from event;
+--------+------------------+----+
| name   | value            | id |
+--------+------------------+----+
| nba    | i love this game |  1 |
| it     | baidu            |  2 |
| spring | spring in action |  3 |
| nba    | i am back        |  4 |
+--------+------------------+----+
4 rows in set (0.00 sec)


mysql> insert into event values('tt','aaa',5);
Query OK, 1 row affected (0.00 sec)


mysql> commit;
Query OK, 0 rows affected (0.00 sec)


mysql> select * from event;
+--------+------------------+----+
| name   | value            | id |
+--------+------------------+----+
| nba    | i love this game |  1 |
| it     | baidu            |  2 |
| spring | spring in action |  3 |
| nba    | i am back        |  4 |
| tt     | aaa              |  5 |
+--------+------------------+----+
5 rows in set (0.00 sec)


可以看到在第二个窗口即时是提交了修改,在第一个窗口也依然看不到提交的数据。上面的查询是可以看见的,update是不可见的

mysql的客户端在连接超时端开后,对应的事务是不会提交或回滚的,依然还在,这个时候就会出现莫名其妙的锁定问题。

*************************** 2. row ***************************
                    trx_id: 8834
                 trx_state: RUNNING
               trx_started: 2016-06-22 12:09:15
     trx_requested_lock_id: NULL
          trx_wait_started: NULL
                trx_weight: 3
       trx_mysql_thread_id: 34
                 trx_query: NULL
       trx_operation_state: NULL
         trx_tables_in_use: 0
         trx_tables_locked: 0
          trx_lock_structs: 3
     trx_lock_memory_bytes: 1184
           trx_rows_locked: 13
         trx_rows_modified: 0
   trx_concurrency_tickets: 0
       trx_isolation_level: SERIALIZABLE
         trx_unique_checks: 1
    trx_foreign_key_checks: 1
trx_last_foreign_key_error: NULL
 trx_adaptive_hash_latched: 0
 trx_adaptive_hash_timeout: 10000
          trx_is_read_only: 0
trx_autocommit_non_locking: 0
*************************** 3. row ***************************
                    trx_id: 8833
                 trx_state: RUNNING
               trx_started: 2016-06-22 12:09:10
     trx_requested_lock_id: NULL
          trx_wait_started: NULL
                trx_weight: 2
       trx_mysql_thread_id: 35
                 trx_query: NULL
       trx_operation_state: NULL
         trx_tables_in_use: 0
         trx_tables_locked: 0
          trx_lock_structs: 2
     trx_lock_memory_bytes: 360
           trx_rows_locked: 13
         trx_rows_modified: 0
   trx_concurrency_tickets: 0
       trx_isolation_level: SERIALIZABLE
         trx_unique_checks: 1
    trx_foreign_key_checks: 1
trx_last_foreign_key_error: NULL
 trx_adaptive_hash_latched: 0
 trx_adaptive_hash_timeout: 10000
          trx_is_read_only: 0
trx_autocommit_non_locking: 0