How do I turn off autocommit for a MySQL client?

后端 未结 7 709
灰色年华
灰色年华 2020-12-13 06:36

I have a web app that has been written with the assumption that autocommit is turned on on the database, so I don\'t want to make any changes there. However all the document

7条回答
  •  醉话见心
    2020-12-13 07:06

    You do this in 3 different ways:

    1. Before you do an INSERT, always issue a BEGIN; statement. This will turn off autocommits. You will need to do a COMMIT; once you want your data to be persisted in the database.

    2. Use autocommit=0; every time you instantiate a database connection.

    3. For a global setting, add a autocommit=0 variable in your my.cnf configuration file in MySQL.

提交回复
热议问题