且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从MySQL中的存储过程打印调试信息

更新时间:2021-10-13 15:52:25

选项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.