在MySQL语句中嵌入注释 [英] Embedding comments in MySQL statements

查看:118
本文介绍了在MySQL语句中嵌入注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人知道在MySQL语句中嵌入注释的方法?当我搜索mysql和评论,我得到只有的方式,在表格等中的注释。

Does anyone know of a way to embed comments in MySQL statements? When I search for mysql and comments I get only ways to put comments in tables, etc

这个想法,如果我实现这个方式我的老板想要的是, (通过二进制日志)我们知道谁做了什么。

The idea, if I implement this the way my boss wants it, is to prepend the user id to the statement apparently so that when MySQL is analyzed later (via the binary log) we know who did what.

例子:

SELECT id

FROM customer

WHERE handle ='JBH'



现在显示为:

- user:jwilkie

SELECT id

FROM customer

WHERE handle ='JBH'

Example:
SELECT id
FROM customer
WHERE handle='JBH'

Would now show up as:
-- user:jwilkie
SELECT id
FROM customer
WHERE handle='JBH'

(或类似的)

(or similar)

EDIT FOR CLARITY: perl模块,我们通过读取$ ENV {USER}(在这种情况下是jwilkie)检索用户ID。这是一种情况,我们有一个MySQL用户定义,但多个人运行perl mod。

EDIT FOR CLARITY: The reason for this is that we have perl modules that are interfacing with MySQL and we are retrieving the user id by reading $ENV{USER} (which in this case is "jwilkie"). It is a situation where we have one MySQL user defined but multiple people running the perl mod.

有没有人有这方面的经验?非常感谢! Jane

Does anyone have experience with this? Many many thanks! Jane

推荐答案

通常,在将SQL语句记录在二进制日志中之前,注释将被删除。然而,一个讨厌的解决方法是假装ypur注释包含一些未来版本的MySQL的语法 - 例如。 9.99.99:

Normally, comments are stripped before the SQL statement is recorded in the binary log. However, a nasty workaround is to pretend that ypur comment contains syntax for some future version of MySQL - eg. 9.99.99:

/*!99999 user:jwilkie */ insert into tbl values (yyy);

这些注释将被传递到二进制日志中。

These comments will then be passed through into the binary log.

这篇关于在MySQL语句中嵌入注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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