Print debugging info from stored procedure in MySQL

后端 未结 5 2090
滥情空心
滥情空心 2020-12-12 18:32

Is there a way in MySQL to print debugging messages to stdout, temptable or logfile? Something like:

  • print in SQLServer
  • DBMS_OUTPU
5条回答
  •  既然无缘
    2020-12-12 19:11

    This is the way how I will debug:

    CREATE PROCEDURE procedure_name() 
    BEGIN
        DECLARE EXIT HANDLER FOR SQLEXCEPTION
        BEGIN
            SHOW ERRORS;  --this is the only one which you need
            ROLLBACK;   
        END; 
        START TRANSACTION;
            --query 1
            --query 2
            --query 3
        COMMIT;
    END 
    

    If query 1, 2 or 3 will throw an error, HANDLER will catch the SQLEXCEPTION and SHOW ERRORS will show errors for us. Note: SHOW ERRORS should be the first statement in the HANDLER.

提交回复
热议问题