Take the 2-minute tour ×
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. It's 100% free, no registration required.

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

[mysqld]
autocommit=0

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.

[mysqld]
autocommit=0
execute_sql="Custom SQL to set autocommit for a database"
share|improve this question

1 Answer 1

up vote 0 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

[mysqld]
init-file=/var/lib/mysql/init-file.sql

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 !!!

CAVEAT

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:

[client]
autocommit=0

or

[mysql]
autocommit=0

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

 
discard

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.