1、set autocommit=off 设置回话级别的禁止
2、要设置全局的可以通过三种方式
i set global init_connect='set autocommit=0';
ii 在初始化参数文件中设置
在[mysqld]
加入init_connect='set autocommit=0'
iii 在mysql 启动的时候加参数
–init_connect='SET autocommit=0'
实验一:
[
root@mysql mysql]#
mysql -uroot -p1qazxsw2----super 用户登入设置全局
mysql> set global init_connect="set autocommit=0";
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
[ root@mysql mysql]# mysql -uhuzhicheng -phuzhicheng---普通用户进去查询是否生效
mysql> show variables like 'autocommit';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| autocommit | OFF |
+---------------+-------+
1 row in set (0.00 sec)
mysql> exit
Bye
[ root@mysql mysql]# /etc/init.d/mysql stop
Shutting down MySQL.. [ OK ]
[ root@mysql mysql]# /etc/init.d/mysql start
Starting MySQL. [ OK ] -----重启数据库
[ root@mysql mysql]# mysql -uhuzhicheng -phuzhicheng
mysql> show variables like 'autocommit';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| autocommit | ON |-------------设置的全局无效
+---------------+-------+
1 row in set (0.00 sec)
mysql>
mysql> set global init_connect="set autocommit=0";
Query OK, 0 rows affected (0.00 sec)
mysql> exit
Bye
[ root@mysql mysql]# mysql -uhuzhicheng -phuzhicheng---普通用户进去查询是否生效
mysql> show variables like 'autocommit';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| autocommit | OFF |
+---------------+-------+
1 row in set (0.00 sec)
mysql> exit
Bye
[ root@mysql mysql]# /etc/init.d/mysql stop
Shutting down MySQL.. [ OK ]
[ root@mysql mysql]# /etc/init.d/mysql start
Starting MySQL. [ OK ] -----重启数据库
[ root@mysql mysql]# mysql -uhuzhicheng -phuzhicheng
mysql> show variables like 'autocommit';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| autocommit | ON |-------------设置的全局无效
+---------------+-------+
1 row in set (0.00 sec)
mysql>
以上说明 设置全局的是只在服务器启动期间有效重启后失效,而且super 用户设置后对super用户是无效的。
实验2:修改参数文件
重启数据库
[
root@mysql mysql]# /etc/init.d/mysql stop
Shutting down MySQL.. [ OK ]
[ root@mysql mysql]# /etc/init.d/mysql start
Starting MySQL. [ OK ]
[ root@mysql mysql]# mysql -uhuzhicheng -phuzhicheng
mysql> show variables like 'autocommit';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| autocommit | OFF | ----针对普通用户有效
+---------------+-------+
1 row in set (0.00 sec)
mysql> exit
Bye
[ root@mysql mysql]# mysql -uroot -p1qazxsw2
mysql> show variables like 'autocommit';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| autocommit | ON |------ 针对supper用户无效
+---------------+-------+
1 row in set (0.00 sec)
mysql>
Shutting down MySQL.. [ OK ]
[ root@mysql mysql]# /etc/init.d/mysql start
Starting MySQL. [ OK ]
[ root@mysql mysql]# mysql -uhuzhicheng -phuzhicheng
mysql> show variables like 'autocommit';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| autocommit | OFF | ----针对普通用户有效
+---------------+-------+
1 row in set (0.00 sec)
mysql> exit
Bye
[ root@mysql mysql]# mysql -uroot -p1qazxsw2
mysql> show variables like 'autocommit';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| autocommit | ON |------ 针对supper用户无效
+---------------+-------+
1 row in set (0.00 sec)
mysql>
实验三:
带命令行参数启动暂时还不会 突突...........................
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26764973/viewspace-1449816/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26764973/viewspace-1449816/