SET sql_mode=(SELECT REPLACE(@@sql_mode,‘ONLY_FULL_GROUP_BY’,’’));
show GLOBAL VARIABLES like ‘%isolation%’ #查询全局事务的隔离级别;
create table account(
id int(10) PRIMARY key not null,
name VARCHAR(40),
money DOUBLE
);
INSERT into account VALUES (1,‘dingning’,200);
INSERT into account VALUES (2,‘huangzhihuan’,400);
#提交事务的测试:
BEGIN;
update account set money = money + 100 where name = ‘huangzhihuan’;
COMMIT;
select * from account;
#事务回滚的测试
BEGIN;
update account set money = money - 100 where name = ‘huangzhihuan’;
rollback;
select * from account;
#多点回滚:
BEGIN;
update account set money = money + 100 where name = ‘dingning’;
SAVEPOINT d; #回滚点的名称可以自定义
update account set money = money + 100 where name = ‘huangzhihuan’;
SAVEPOINT d1
INSERT into account VALUES (3,‘chenwei’,200);
select * from account;
rollback to d;
select * from account;
#事务的控制:
SHOW VARIABLES like ‘autocommit’; #查看自动提交事务的功能;
set autocommit=0; #禁止自动提交;
set autocommit=1; #开启自动提交;
#存储引擎:
show ENGINES; #查看系统支持的存储引擎;
show table status from kgc where name = ‘ky08’; #查看表使用的存储引擎;
alter table ky08 ENGINE=myisam; #修改表的存储引擎;