Print debugging info from stored procedure in MySQL

Viewed 259080

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

  • print in SQLServer
  • DBMS_OUTPUT.PUT_LINE in Oracle
5 Answers

Quick way to print something is:

select '** Place your mesage here' AS '** DEBUG:';

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.

Related