如何显示在MySQL上执行的最后一个查询? [英] How to show the last queries executed on MySQL?

查看:134
本文介绍了如何显示在MySQL上执行的最后一个查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何查询/方式来显示在 ALL 个服务器上执行的最后一个查询?

Is there any query/way to show the last queries executed on ALL servers?

推荐答案

对于那些使用MySQL> = 5.1.12的人来说,可以在运行时全局控制此选项:

For those blessed with MySQL >= 5.1.12, you can control this option globally at runtime:

  1. 执行SET GLOBAL log_output = 'TABLE';
  2. 执行SET GLOBAL general_log = 'ON';
  3. 看看表mysql.general_log
  1. Execute SET GLOBAL log_output = 'TABLE';
  2. Execute SET GLOBAL general_log = 'ON';
  3. Take a look at the table mysql.general_log

如果您希望输出到文件而不是表:

If you prefer to output to a file instead of a table:

  1. SET GLOBAL log_output = "FILE"; 默认.
  2. SET GLOBAL general_log_file = "/path/to/your/logfile.log";
  3. SET GLOBAL general_log = 'ON';
  1. SET GLOBAL log_output = "FILE"; the default.
  2. SET GLOBAL general_log_file = "/path/to/your/logfile.log";
  3. SET GLOBAL general_log = 'ON';

我更喜欢这种方法来编辑.cnf文件,因为:

I prefer this method to editing .cnf files because:

  1. 您不编辑my.cnf文件,并可能永久打开日志记录
  2. 您不会在文件系统中四处寻找查询日志-甚至更糟的是,由于需要完美的目的地而分心. /var/log /var/data/log /opt /home/mysql_savior/var
  3. 您不必重新启动服务器并中断与服务器的任何当前连接.
  4. 重新启动服务器会将您留在开始的位置(默认情况下,日志仍处于关闭状态)
  1. you're not editing the my.cnf file and potentially permanently turning on logging
  2. you're not fishing around the filesystem looking for the query log - or even worse, distracted by the need for the perfect destination. /var/log /var/data/log /opt /home/mysql_savior/var
  3. You don't have to restart the server and interrupt any current connections to it.
  4. restarting the server leaves you where you started (log is by default still off)

有关更多信息,请参见 MySQL 5.1参考手册-服务器系统变量-general_log

For more information, see MySQL 5.1 Reference Manual - Server System Variables - general_log

这篇关于如何显示在MySQL上执行的最后一个查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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