2. 建立表時如果不指定type則預設為myisam,不支援事務。
可以用 show create table tablename 命令看錶的類型。
2.1 對不支援事務的表做start/commit操作沒有任何效果,在執行commit前已經提交,測試:
執行一個msyql:
use test;
drop table if exists tn;
create table tn (a varchar(10)) type=myisam;
drop table if exists ty;
create table ty (a varchar(10)) type=innodb;
begin;
insert into tn values('a');
insert into ty values('a');
select * from tn;
select * from ty;
都能看到一條記錄
執行另一個mysql:
use test;
select * from tn;
select * from ty;
只有tn能看到一條記錄
然後在另一邊
commit;
才都能看到記錄。
3. 可以執行以下命令來切換非事務表到事務(資料不會丟失),innodb表比myisam表更安全:
alter table tablename type=innodb;