mysql禁用autocommit,以及遇到的问题(转)
MySQL的autocommit(自动提交)默认是开启,其对mysql的性能有一定影响,举个例子来说,如果你插入了1000条数据,mysql会commit1000次的,如果我们把autocommit关闭掉,通过程序来控制,只要一次commit就可以了。
1,我们可以通过set来设置autocommit
- mysql> set global init_connect="set autocommit=0"; //提示你用权限更高的财户来设置
- ERROR 1227 (42000): Access denied; you need (at least one of) the SUPER privilege(s) for this operation
- mysql> set autocommit=0;
- Query OK, 0 rows affected (0.00 sec)
- mysql> select @@autocommit; //查看一下autocommit的设置
- +--------------+
- | @@autocommit |
- +--------------+
- | 0 |
- +--------------+
- 1 row in set (0.00 sec)
2,我们可以修改mysql的配置文件my.cnf来关闭autocommit
- [mysqld]
- init_connect='SET autocommit=0' //在mysqld里面加上这些内容
用第二种方法关,有一点要注意,连接mysql用户的权限不能大于启动mysql的用户的权限,不然init_connect='SET autocommit=0'根本不会启作用,也不会报任何错误,汗一个先。看以下实例
- zhangy@ubuntu:~$ mysql -umysql
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 1
- Server version: 5.5.2-m2-log Source distribution
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- mysql> select @@autocommit; //mysql是启动用户,关闭autocommit成功
- +--------------+
- | @@autocommit |
- +--------------+
- | 0 |
- +--------------+
- 1 row in set (0.00 sec)
- mysql> Ctrl-C -- exit!
- Aborted
- zhangy@ubuntu:~$ mysql -uroot
- Welcome to the MySQL monitor. Commands end with ; or \g.
- Your MySQL connection id is 2
- Server version: 5.5.2-m2-log Source distribution
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- mysql> select @@autocommit; //用root财户启动,不成功。
- +--------------+
- | @@autocommit |
- +--------------+
- | 1 |
- +--------------+
- 1 row in set (0.00 sec)
这个会不会是mysql的bug呢?我在网上找了找这方面的问题,还真有。部分内容如下:
If a user has SUPER privilege, init_connect will not execute
(otherwise if init_connect will a wrong query no one can connect to server).
Note, if init_connect is a wrong query, the connection is closing without any errors
and next command will clause 'lost connection' error.
里面有一点说的很清楚If a user has SUPER privilege, init_connect will not execute,如果用户有更高级的权限,init_connect根本不会执行。
http://blog.csdn.net/ying_593254979/article/details/12095169
mysql禁用autocommit,以及遇到的问题(转)的更多相关文章
- mysql禁用autocommit,以及遇到的问题
原文地址:http://blog.51yip.com/mysql/1230.html http://blog.csdn.net/ying_593254979/article/details/12095 ...
- 关于mysql 的 autoCommit 参数
首先描述一下这个参数的作用. 这个参数 默认是开启的. 开启以后再命令敲的sql 会自动提交.如果关闭,就必须手动 commit. 查看 这个 自动提交状态. SELECT @@autocommit; ...
- Mysql中autocommit的用法
定义 Mysql文档原文:SET autocommit disables or enables the default autocommit mode for the current session. ...
- MySQL 的 autocommit
在自动提交模式(autocommit=ON)下提交事务: •在自动提交模式下,每个SQL语句都是一个独立的事务. –mysql>insert into ACCOUNTS values(1,'To ...
- 【mysql】autocommit=0后,commit, rollback无效
之前在[mysql]MySQLdb中的事务处理中用autocommit和commit()以及rollback()实现了事务处理. 但后来,用同样的代码在另一个数据库中运行却失败了.找了一个下午的原因. ...
- 从知乎了解到,为什么Mysql禁用存储过程、外键和级联?
打开帖子直接一张醒目的图,是阿里巴巴的Java开发手册对Mysql相关的要求. 看看下面的回复 灵剑 存储过程没有版本控制,版本迭代的时候要更新很麻烦.存储过程如果和外部程序结合起来用,更新的时候很难 ...
- mysql事务,SET AUTOCOMMIT,START TRANSACTION
http://yulei568.blog.163.com/blog/static/135886720071012444422/ MyISAM不支持 START TRANSACTION | BEGIN ...
- mysql事务,START TRANSACTION, COMMIT和ROLLBACK,SET AUTOCOMMIT语法
http://yulei568.blog.163.com/blog/static/135886720071012444422/ MyISAM不支持 START TRANSACTION | BEGIN ...
- mysql java.sql.SQLException: Can't call commit when autocommit=true
java.sql.SQLException: Can't call commit when autocommit=true at com.mysql.jdbc.SQLError.createSQLEx ...
随机推荐
- Android中使用NDK
首先用Android Studio下载NDK 这个比较简单,就不多说了 1.写调用jni的Java代码 新建一个JniUtils类 public class JniUtils { static { S ...
- ZOJ 1093 Monkey and Banana (LIS)解题报告
ZOJ 1093 Monkey and Banana (LIS)解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...
- ACE6.2.0文件/目录操作
文件读取.#include "ace/FILE_Connector.h"#include "ace/FILE_IO.h"void fileRW(){ACE_FI ...
- JavaSE学习总结第23天_多线程1
23.01 多线程程序的引入 如果一个程序只有一个执行流程,所以这样的程序就是单线程程序. 如果一个程序有多条执行流程,那么,该程序就是多线程程序. 23.02 进程概述及多进程的意义 要想说 ...
- iframe,modaldialog父子窗口相互通信的问题
--- 子窗口访问父窗口的window对象 --- 打开新窗口一般有几种方法,window.open(...),window.showModalDialog(...),以及iframe中嵌套页面,另外 ...
- mysqld守护进程
1.安装方式:安装文件:可执行的二进制文件: 源代码编译. 2.版本选择:常见版本区别:GA(一般应用,尽量使用最新版本)/RC(候选发布版本)/测试版本实版本选择主要是够用.适用.好用!不一定是最新 ...
- JavaEE Tutorials (4) - 企业bean入门
4.1创建企业bean52 4.1.1编写企业bean类53 4.1.2创建converter Web客户端53 4.1.3运行converter示例544.2修改Java EE应用55 4.2.1修 ...
- jQuery报错:Uncaught ReferenceError: $ is not defined
在使用jQuery的时候,发现有如下报错: Uncaught ReferenceError: $ is not defined (anonymous function) 出现这个报错的原因: 1.j ...
- android软键盘enter键
enter键,回车键,电脑键盘上enter键就有多种响应.android软键盘也不例外 你在EditText上输入以后,想在下一行输入框输入,可能需要去点击下一行输入框,让它获取焦点,也可能要隐藏软键 ...
- git 使用过程(四、回退版本)
1.查看修改历史 命令:git log 如果嫌内容太多 可以加参数 --pretty=oneline (图一) 2.回退 命令:git reset --hard HEAD^ HEAD:代表本 ...