关于Msyql的事务

王朝delphi·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

0. 参见 mysql\Docs\manual.html

1. 4.0以上mysqld都支持事务,包括非max版本。3.23的需要max版本mysqld才能支持事务。

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;

3.1 innodb表不能用repair table命令和myisamchk -r table_name

但可以用check table,以及mysqlcheck [OPTIONS] database [tables]

4. 启动mysql数据库的命令行中添加了以下参数可以使新发布的mysql数据表都默认为使用事务(

只影响到create语句。)

--default-table-type=InnoDB

测试命令:

use test;

drop table if exists tn;

create table tn (a varchar(10));

show create table tn;

5. 临时改变默认表类型可以用:

set table_type=InnoDB;

show variables like 'table_type';

或:

c:\mysql\bin\mysqld-max-nt --standalone --default-table-type=InnoDB

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航