博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
从MySQL中的存储过程打印调试信息(Print debugging info from stored procedure in MySQL)
阅读量:4223 次
发布时间:2019-05-26

本文共 1297 字,大约阅读时间需要 4 分钟。

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

解决方案

 

Option 1: Put this in your procedure to print 'comment' to stdout when it runs.

SELECT 'Comment';

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);

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

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);

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));

Which saves a few keystrokes.

Option 4, Log messages to file

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

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.

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.

转载地址:http://yyemi.baihongyu.com/

你可能感兴趣的文章
Sweet Snippet 系列之 Lua表排序
查看>>
名人•牛人•我们这些普通人
查看>>
小话游戏脚本(一)
查看>>
数学笔记(二)之平面表示
查看>>
HGE系列之零 使用细究
查看>>
爬坑笔记
查看>>
再谈谈列表元素的删除
查看>>
小聊聊NGUI中Panel的Clip功能(之二)
查看>>
构造函数与析构函数
查看>>
C++中的new和delete在类中的应用
查看>>
C++中构造函数和析构函数的执行顺序
查看>>
英文论文中“such as, for example, e.g., i.e., etc., et al. ”的用法分析
查看>>
C与C++中string的区别与联系
查看>>
OpenGL学习网站及资料
查看>>
数字图像处理基本知识--笔记一
查看>>
傅里叶变换的通俗理解
查看>>
傅里叶变换理解之二
查看>>
最大公共字串问题
查看>>
面试经
查看>>
男女比例问题
查看>>