How do you debug MySQL stored procedures?

后端 未结 16 1247
旧时难觅i
旧时难觅i 2020-11-30 17:44

My current process for debugging stored procedures is very simple. I create a table called \"debug\" where I insert variable values from the stored procedure as it runs. Thi

16条回答
  •  一生所求
    2020-11-30 17:57

    Debugger for mysql was good but its not free. This is what i use now:

    DELIMITER GO$
    
    DROP PROCEDURE IF EXISTS resetLog
    
    GO$
    
    Create Procedure resetLog() 
    BEGIN   
        create table if not exists log (ts timestamp default current_timestamp, msg varchar(2048)) engine = myisam; 
        truncate table log;
    END; 
    
    GO$
    
    DROP PROCEDURE IF EXISTS doLog 
    
    GO$
    
    Create Procedure doLog(in logMsg nvarchar(2048))
    BEGIN  
      insert into log (msg) values(logMsg);
    END;
    
    GO$
    

    Usage in stored procedure:

    call dolog(concat_ws(': ','@simple_term_taxonomy_id',  @simple_term_taxonomy_id));
    

    usage of stored procedure:

    call resetLog ();
    call stored_proc();
    select * from log;
    

提交回复
热议问题