MySQLはデータベースをまたぐトランザクションを行える

MySQL

以下に検証結果

mysql> create table test.aaa (bbb int(11));
mysql> create table test2.aaa (bbb int(11));
mysql> begin;
Query OK, 0 rows affected (0.00 sec)

mysql> insert into test.aaa values(1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into test.aaa values(1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into test.aaa values(1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into test.aaa values(1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into test2.aaa values(1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into test2.aaa values(1);
Query OK, 1 row affected (0.00 sec)

mysql> insert into test2.aaa values(1);
Query OK, 1 row affected (0.00 sec)

mysql> select count(*) from test.aaa;
+----------+
| count(*) |
+----------+
|        4 |
+----------+
1 row in set (0.00 sec)

mysql> select count(*) from test2.aaa;
+----------+
| count(*) |
+----------+
|        3 |
+----------+
1 row in set (0.00 sec)

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

mysql> select count(*) from test.aaa;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.01 sec)

mysql> select count(*) from test2.aaa;
+----------+
| count(*) |
+----------+
|        0 |
+----------+
1 row in set (0.00 sec)

mysql> show variables like 'version';
+---------------+-----------+
| Variable_name | Value     |
+---------------+-----------+
| version       | 5.5.8-log |
+---------------+-----------+
1 row in set (0.00 sec)


Comments

タイトルとURLをコピーしました