Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In MySQL's configuration file I've globally disabled autocommit as so.


I need to turn MySQL's autocommit on for a specific Ruby on Rails database though. It could be for the user or the database itself (doesn't matter). Thinking it would look something like this.

execute_sql="Custom SQL to set autocommit for a database"
share|improve this question
up vote 1 down vote accepted

Let's say

  • you are using MySQL in Linux
  • datadir is /var/lib/mysql

You could use the init-file option

You could just create an init file called /var/lib/mysql/init-file.sql

Put the customer SQL in /var/lib/mysql/init-file.sql

You could then try one of two things

Try #1

Add this to /etc/my.cnf


then run

service mysql restart

Try #2

Directly run this

service mysql restart --init-file=/var/lib/mysql/init-file.sql

Give it a Try !!!


That was a global setting of init code. If your session has to enable autocommit, then just run

SET autocommit=0

in the session or put SET AUTOCOMMIT=0 in the init-file option file. This may still not produce the effect you want since everything goes back to default settings upon connection termination.

UPDATE 2013-02-28 15:40 EST

If you are looking for a startup option for my.cnf to affect the client, try this:




Perhaps try adding another my.cnf in the Linux home directory with these options

For more information, see the MySQL Options File Documentation

share|improve this answer
I really like the abstraction into a separate file here. – Ash Blue Feb 28 '13 at 20:29
Does a similar inline command exist such as init-command="mysql here". I saw that on a few StackOverflow pages, but it throws an error. – Ash Blue Feb 28 '13 at 20:36
Updated my answer... – RolandoMySQLDBA Feb 28 '13 at 20:40
I'm able to get things loading from the file, but unable to toggle autocommit=0 for a specific user or database. – Ash Blue Feb 28 '13 at 21:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.