从MySQL中的存储过程打印调试信息 [英] Print debugging info from stored procedure in MySQL

查看:12863
本文介绍了从MySQL中的存储过程打印调试信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在MySQL中有没有办法将调试消息打印到stdout,诱人或日志文件?如下所示:

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


  • 打印在SQLServer

  • < $ DBMS_OUTPUT.PUT_LINE 在Oracle
  • print in SQLServer
  • DBMS_OUTPUT.PUT_LINE in Oracle

推荐答案

选项1:将其放在您的程序中,以便在运行时打印注释为stdout。

SELECT 'Comment';

选项2:将这个在您的过程中打印一个变量到stdout: / strong>

Option 2: Put this in your procedure to print a variable with it to stdout:

declare myvar INT default 0;
SET myvar = 5;
SELECT concat('myvar is ', myvar);

这将打印 myvar is 5 to stdout when程序运行。

This prints myvar is 5 to stdout when the procedure runs.

选项3,创建一个名为 tmptable 的文本列的表,然后推消息:

Option 3, Create a table with one text column called tmptable, and push messages to it:

declare myvar INT default 0;
SET myvar = 5;
insert into tmptable select concat('myvar is ', myvar);

您可以将上述内容放在一个存储过程中,所以你必须写的是这样的: / p>

You could put the above in a stored procedure, so all you would have to write is this:

CALL log(concat('the value is', myvar));

其中保存了一些按键。

选项4,将消息记录到文件

Option 4, Log messages to file

select "penguin" as log into outfile '/tmp/result.txt';

这个命令有很大的限制。您只能将outfile写入磁盘上的其他人组创建和写入权限的区域。它应该工作保存到/ tmp目录。

There is very heavy restrictions on this command. You can only write the outfile to areas on disk that give the 'others' group create and write permissions. It should work saving it out to /tmp directory.

此外,一旦你写出outfile,你不能覆盖它。这是为了防止饼干生根,因为他们有SQL注入您的网站,并可以在MySQL中运行任意命令。

Also once you write the outfile, you can't overwrite it. This is to prevent crackers from rooting your box just because they have SQL injected your website and can run arbitrary commands in MySQL.

这篇关于从MySQL中的存储过程打印调试信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆