MySQL – How to Turn Off Autocommit in phpMyAdmin

innodbMySQLphpmyadmin

I want to practice rolling back commands, savepoints and more on phpMyAdmin but I couldn't find a way to turn off autocommit in phpMyadmin. Currently I use the command SET autocommit = 0;.

I want to know how, instead of typing this command before each query, if there is another way to perform this task?

Best Answer

You can do this in 3 different ways:

The best answer to this question depends on the context of your request.

If you are doing this from time to time on a dev/test machine (and I certainly hope you're not doing it on an important/production one!), you can then afford to make global changes and you could:

  • Edit the database interface file inside the "libraries" folder as described here and put the line SET AUTOCOMMIT = 1; in the postConnect function. This will affect every connection made from that instance of phpMyAdmin - you may or may not want this, depending on whether you also use that machine's phpMyAdmin for running stuff on prod?

  • Put the line autocommit = 0 to set the variable in your my.cnf/my.ini. This now means that every connection to that server will automatically commit (described here). Again, you may or may not want to do this.

  • Finally, if this is something that you'll want to do from time to time - i.e. experiment at lunchtime/whatever, you can issue a BEGIN [WORK] before you issue your SQL statements! (ibid - aliases of START TRANSACTION - see here).

    This has the advantage of not affecting the configuration of either phyMyAdmin or the MySQL server, BUT has the disadvantage of the dev (i.e. you) having to remember to put it in each time. NOT advisable on a production machine, but means that you can use your db tool on both work systems and your experimental ones without worry!

The choice is yours!