MySQL存储过程中使用事务

    技术2022-05-20  33

    事务用起来很简单

    start transaction;

    .

    .

    .

     commit;    // 如果不commit,则之前的操作只为临时变更,在数据库重启后变消失了,不会作为永久变更

     

    -- 例子

    drop procedure if exists Pro_Commit; create procedure Pro_Commit() begin  start transaction;  insert into Shop (ShopID, ShopName) values ('222', '222');  commit;    end call Pro_Commit(); select * from Shop;

     

     

    但是要注意:使用事务的话,mysql必须设置为非Autocommit,方法如下:

    [mysqld] init_connect= 'SET   AUTOCOMMIT=0 '


    最新回复(0)