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;