MySQL disable autocommit, as well as the problems encountered

Source: Internet
Author: User

MySQL autocommit (auto-commit) is on by default, it has a certain impact on MySQL performance, for example, if you insert 1000 data, MySQL will commit1000 times, if we put autocommit off, through the program to control , only one commit is allowed.

1, we can set the autocommit

View copy print?
  1. Mysql> set global init_connect="set autocommit=0"; //Prompt you to set up with a higher-privileged financial account
  2. ERROR 1227 (42000): Access denied; Need (at least one's) the SUPER privilege (s) for this operation
  3. Mysql> set autocommit=0;
  4. Query OK, 0 rows Affected (0.00 sec)
  5. Mysql> SELECT @ @autocommit; //Check the settings of the autocommit
  6. +--------------+
  7. | @ @autocommit |
  8. +--------------+
  9. | 0 |
  10. +--------------+
  11. 1 row in Set (0.00 sec)

2, we can modify the MySQL configuration file my.cnf to close autocommit

View copy print?
    1. [Mysqld]
    2. init_connect=' SET autocommit=0 ' //Add these to mysqld

With the second method off, one thing to note, the access to the MySQL user can not be greater than the rights to start the MySQL user, otherwise init_connect= ' SET autocommit=0 ' will not function, will not report any errors , sweat a first. See the following example

View copy print?
  1. [Email protected]:~$ mysql-umysql
  2. Welcome to the MySQL Monitor. Commands End With;  or \g.
  3. Your MySQL Connection ID is 1
  4. Server Version:5.5.2-m2-log Source Distribution
  5. Type ' help; ' or ' \h ' for help .  Type ' \c ' to clear the current input statement.
  6. Mysql> SELECT @ @autocommit; //mysql is the start user, shutdown autocommit successful
  7. +--------------+
  8. | @ @autocommit |
  9. +--------------+
  10. | 0 |
  11. +--------------+
  12. 1 row in Set (0.00 sec)
  13. Mysql> ctrl-c-- exit!
  14. Aborted
  15. [Email protected]:~$ mysql-uroot
  16. Welcome to the MySQL Monitor. Commands End With;  or \g.
  17. Your MySQL Connection ID is 2
  18. Server Version:5.5.2-m2-log Source Distribution
  19. Type ' help; ' or ' \h ' for help .  Type ' \c ' to clear the current input statement.
  20. Mysql> SELECT @ @autocommit;  //Start with root account, unsuccessful.
  21. +--------------+
  22. | @ @autocommit |
  23. +--------------+
  24. | 1 |
  25. +--------------+
  26. 1 row in Set (0.00 sec)

Will this be a MySQL bug? I looked for this question on the Internet, and there really was. Some of the contents are as follows:
If a user has SUPER privilege, Init_connect would not execute
(otherwise if Init_connect would a wrong query no one can connect to server).

Note, if Init_connect is a wrong query, the connection was closing without any errors
And next command would clause ' Lost connection ' error.

It's a little clear in there. If a user has SUPER privilege, Init_connect would not execute, Init_connect does not execute if the user has more advanced permissions.

http://blog.csdn.net/ying_593254979/article/details/12095169

MySQL disable autocommit, as well as the problems encountered (GO)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.