代码之家  ›  专栏  ›  技术社区  ›  reto

ruby mysql将所有语句记录到stdout/console

  •  1
  • reto  · 技术社区  · 15 年前

    使用RubyMySQL时,如何将所有执行的SQL语句记录到console/stdout中?

    类似于从rails输出的log/development.log。

    2 回复  |  直到 12 年前
        1
  •  1
  •   rjp    15 年前

    如果你是说 Ruby/MySQL ,它提供一个debug()函数,该函数与 mysql_debug() --如果您的客户机库是通过调试编译的,那么您可以 DBUG to trace things 为你。这可能会给你想要的东西(稍微清理一下)。

    另一种方法是 capture the MySQL packets using tcpdump and decode them with maatkit .

    第三种方法是 alias Mysql.query and Mysql.real_query with your own functions 那就是伐木。像这样的东西( 未经测试的 !微不足道的例子!不处理块!):

    class Mysql
      alias_method :old_query, :query
      def query(sql)
        $stderr.puts "SQL: #{sql}"
        old_query(sql)
      end
    end
    
        2
  •  0
  •   khelll    15 年前

    Rails使用类似ActiveRecord的窗体,该窗体具有与之关联的记录器。 我认为mysql gem没有日志记录程序…