您好,欢迎来到微智科技网。
搜索
您的当前位置:首页Innodb表类型中autocommit的设置

Innodb表类型中autocommit的设置

来源:微智科技网

此为原创:转载请注明出处;
作者:小宝(ilsanbao)
博客:

autocommit 在mysql5.1 版本以后可以通过mysql命令客户端修改;
查看默认设置:

 mysql>show variables like 'autoc%' #默认为 ON

默认为ON,任何客户端发送的SQL指令都将自动提交给mysql server进行处理。
大家一般在使用中多为on, 这里就不多讲解了。
修改autocommit:

 mysql> set autocommit='Off';
Query OK, 0 rows affected (0.00 sec)

创建一个测试表:

mysql> create table t_autocommit(
    -> id int not null auto_increment,
    -> amount int not null default '0',
    -> primary key(id)
    -> )engine=innodb;
Query OK, 0 rows affected (0.03 sec)

mysql>insert into t_autocommit set amount=1;

这是我们修改amount字段

 mysql>update t_autocommit set amount=amount+10;
             然后查看数据
 mysql> select * from t_autocommit;
 +----+--------+
 | id | amount |
 +----+--------+
 |  1 |     11 | 
 +----+--------+

可以看到已经修改成功,其实不然,我们断开mysql,再重新连接

 mysql> select * from t_autocommit;
 +----+--------+
 | id | amount |
 +----+--------+
 |  1 |     1  | 
 +----+--------+

看到了吧, amount值没有被修改,为什么呢?很简单因为SQL语句没有被自己提交给server端去处理,只是在当前连接中做了相应处理。
注:autocommit变量是session类型的,所做的修改只能在当前连接中有效!

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 7swz.com 版权所有 赣ICP备2024042798号-8

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务