Home > Database > Mysql Tutorial > Mysql中使用事宜

Mysql中使用事宜

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 16:16:07
Original
1275 people have browsed it

Mysql中使用事务 1.创建表 create table account( id int primary key auto_increment, name varchar(20), money double ); insert into account values(null,'aaa',1000); insert into account values(null,'bbb',1000); insert into account values(null,'c

Mysql中使用事务
1.创建表
create table account(
   id int primary key auto_increment,
   name varchar(20),
   money double
);

insert into account values(null,'aaa',1000);
insert into account values(null,'bbb',1000);
insert into account values(null,'ccc',1000);

2、MySQL中事务默认自动提交的,每当执行一条SQL,就会提交一个事务 (一条SQL 就是一个事务)
Oracle 中事务默认 不自动提交,需要在执行SQL 语句后 通过commint 手动提交事务

3、mysql管理事务
方式一 :同时事务管理SQL 语句
start transaction  开启事务
rollback  回滚事务 (将数据恢复到事务开始时状态)
commit   提交事务 (对事务中进行操作,进行确认操作,事务在提交后,数据就不可恢复)

方式二:数据库中存在一个自动提交变量 ,通过 show variables like '%commit%'; ---- autocommint 值是 on,说明开启自动提交
关闭自动提交 set autocommit = off / set autocommit = 0
如果设置autocommit 为 off,意味着以后每条SQL 都会处于一个事务中,相当于每条SQL执行前 都执行 start transaction
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
MySQL stops process
From 1970-01-01 08:00:00
0
0
0
Error when installing mysql on linux
From 1970-01-01 08:00:00
0
0
0
phpstudy cannot start mysql?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template