How do you debug MySQL stored procedures?

后端 未结 16 1177
旧时难觅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

    MySql Connector/NET also includes a stored procedure debugger integrated in visual studio as of version 6.6, You can get the installer and the source here: http://dev.mysql.com/downloads/connector/net/

    Some documentation / screenshots: https://dev.mysql.com/doc/visual-studio/en/visual-studio-debugger.html

    You can follow the annoucements here: http://forums.mysql.com/read.php?38,561817,561817#msg-561817

    UPDATE: The MySql for Visual Studio was split from Connector/NET into a separate product, you can pick it (including the debugger) from here https://dev.mysql.com/downloads/windows/visualstudio/1.2.html (still free & open source).

    DISCLAIMER: I was the developer who authored the Stored procedures debugger engine for MySQL for Visual Studio product.

    0 讨论(0)
  • 2020-11-30 17:58

    I just simply place select statements in key areas of the stored procedure to check on current status of data sets, and then comment them out (--select...) or remove them before production.

    0 讨论(0)
  • 2020-11-30 17:59

    The first and stable debugger for MySQL is in dbForge Studio for MySQL

    0 讨论(0)
  • 2020-11-30 18:01

    MySQL Connector/Net 6.6 has a feature to Debug Stored Procedures and Functions

    Installing the Debugger

    To enable the stored procedure debugger:

    • For Connector/Net 6.6: Install Connector/Net 6.6 and choose the Complete option.
    • For Connector/Net 6.7 and later: Install the product MySQL for Visual Studio, to which the stored procedure debugger belongs.

    Starting the Debugger

    To start the debugger, follow these steps:

    • Choose a connection in the Visual Studio Server Explorer.
    • Expand the Stored Procedures folder. Only stored procedures can be debugged directly. To debug a user-defined function, create a stored
      procedure that calls the function.
    • Click on a stored procedure node, then right-click and from the context menu choose Debug Routine.
    0 讨论(0)
  • 2020-11-30 18:01

    I had use two different tools to debug procedures and functions:

    1. dbForge - many functional mysql GUI.
    2. MyDebugger - specialized tool for debugging ... handy tool for debugging.vote http://tinyurl.com/voteimg
    0 讨论(0)
  • 2020-11-30 18:09

    The following debug_msg procedure can be called to simply output a debug message to the console:

    DELIMITER $$
    
    DROP PROCEDURE IF EXISTS `debug_msg`$$
    DROP PROCEDURE IF EXISTS `test_procedure`$$
    
    CREATE PROCEDURE debug_msg(enabled INTEGER, msg VARCHAR(255))
    BEGIN
      IF enabled THEN
        select concat('** ', msg) AS '** DEBUG:';
      END IF;
    END $$
    
    CREATE PROCEDURE test_procedure(arg1 INTEGER, arg2 INTEGER)
    BEGIN
      SET @enabled = TRUE;
    
      call debug_msg(@enabled, 'my first debug message');
      call debug_msg(@enabled, (select concat_ws('','arg1:', arg1)));
      call debug_msg(TRUE, 'This message always shows up');
      call debug_msg(FALSE, 'This message will never show up');
    END $$
    
    DELIMITER ;
    

    Then run the test like this:

    CALL test_procedure(1,2)
    

    It will result in the following output:

    ** DEBUG:
    ** my first debug message
    ** DEBUG:
    ** arg1:1
    ** DEBUG:
    ** This message always shows up
    
    0 讨论(0)
提交回复
热议问题