【问题标题】:Mysql comments information displaymysql评论信息显示
【发布时间】:2018-09-25 17:26:44
【问题描述】:

关于cmets显示的问题,示例如下:

DROP FUNCTION IF EXISTS `foo`;
delimiter //
-- comment1
-- comment2
-- comment3
CREATE FUNCTION foo()
  RETURNS int(1)
BEGIN   
SET @var1 = @var1 + 1;   /* information here */
RETURN @var1;   
END;
//
delimiter ;

show create function foo;

函数 foo 的结果不包含任何 cmets,是否有显示 cmets 仅用于开发目的?

【问题讨论】:

  • 将参考脚本保存在某种形式的外部 .sql 文件中,以备将来开发之用。

标签: mysql comments display


【解决方案1】:

仅当您在函数体中包含 cmets 时。

如果您在 *nix 平台上使用 mysql cli,您可以通过设置 PAGER 来 grep 出 cmets,然后使用 SHOW CREATE PROCEDURE dbname.procedure_name 或查询 information_schema 例程表。之后不要忘记重置 PAGER。

例如

mysql> pager grep '\-\-'
PAGER set to 'grep '\-\-''

mysql> select routine_definition from information_schema.routines where routine_name = 'myaes_convert'\G
  DECLARE gtg TINYINT DEFAULT 0;     -- OK to proceed
  DECLARE vtable_schema VARCHAR(64); -- cursor var
  DECLARE vtable_name VARCHAR(64);   -- cursor var 
    -- Perform Backups on columns
    -- Perform Index backup
    -- Drop indexes
    -- Call column converter
    -- Create triggers on table
    -- Restore indexes and log
    -- rename the table _myaes
    -- create the view for this table
  SELECT 1; -- Phew!
1 row in set (0.02 sec)

mysql> pager
Default pager wasn't set, using stdout.

mysql> pager grep '\-\-'
PAGER set to 'grep '\-\-''

mysql> show create procedure myaes.myaes_convert\G
  DECLARE gtg TINYINT DEFAULT 0;     -- OK to proceed
  DECLARE vtable_schema VARCHAR(64); -- cursor var
  DECLARE vtable_name VARCHAR(64);   -- cursor var 
    -- Perform Backups on columns
    -- Perform Index backup
    -- Drop indexes
    -- Call column converter
    -- Create triggers on table
    -- Restore indexes and log
    -- rename the table _myaes
    -- create the view for this table
  SELECT 1; -- Phew!
1 row in set (0.00 sec)

mysql> pager
Default pager wasn't set, using stdout.

【讨论】:

  • 感谢 Paul,问题仍然存在。这种情况很奇怪,我想原因是相对的,我的帐户没有选择基表mysql.proc的权限。但不确定,我尝试在命令行或 Navicat 中执行许多评论方式但仍然没有评论。
  • 仅在我的数据库上使用和所有权限。
  • 嗯,这就够了,如果你能定义一个函数,你当然可以把它显示回来。我使用我系统上的一个存储过程给出了这种方法的示例,我注意到您正在定义一个函数。您是否在测试时使用了“show create procedure”而不是“show create function”?
  • 是的,我在过去的 MySQL DB 经验中知道这一点。但结果仍然“吃掉”我们的 cmets。如果我们得到它,我们会尝试通过调试过程和反馈来找出根本原因。再次感谢。
  • 嗨,保罗。我们确认我们的 MySQL 数据库代理通过安全原因删除了所有 cmets,以防止 SQL 注入操作。所以这个问题正在解决。谢谢你的帮助!!
猜你喜欢
  • 2013-06-05
  • 1970-01-01
  • 1970-01-01
  • 2011-06-30
  • 2019-06-02
  • 2019-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多