如何找出MySQL数据库在给定时间内执行的所有命令?

发布于 2024-08-02 09:37:53 字数 93 浏览 2 评论 0原文

是否可以找出给定时间范围内对数据库执行的所有命令?例如,我想知道过去 24 小时内谁对数据库表执行了插入命令。

任何帮助将不胜感激。

谢谢。

Is it possible to find out all the command executed against a database in a given timeframe? For example, I would like to know who executed insert command on a database table in the last 24 hours.

Any help would be greatly appreciated.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猥︴琐丶欲为 2024-08-09 09:37:53

对于更改数据的查询,您可以检查二进制日志。但是,我认为这不会让您获得用户:

$ mysqlbinlog /var/log/mysql/mysql-bin.000145
…
# at 3178
#090805  6:25:15 server id 1  end_log_pos 3373  Query   thread_id=2170317       exec_time=0     error_code=0
SET TIMESTAMP=1249467915/*!*/;
UPDATE phpbb3_topics
                SET topic_views = topic_views + 1, topic_last_view_time = 1249467915
                WHERE topic_id = 95847/*!*/;
# at 3373
…

要获得用户,您需要在表上设置触发器并使用这些触发器将审核日志存储在另一个表中。

如果您需要所有查询(包括选择),还有 常规查询日志,但由于性能影响和磁盘要求,该日志通常不会打开。

For queries which change data, you can check the binary log. However, I don't think this'll get you the user:

$ mysqlbinlog /var/log/mysql/mysql-bin.000145
…
# at 3178
#090805  6:25:15 server id 1  end_log_pos 3373  Query   thread_id=2170317       exec_time=0     error_code=0
SET TIMESTAMP=1249467915/*!*/;
UPDATE phpbb3_topics
                SET topic_views = topic_views + 1, topic_last_view_time = 1249467915
                WHERE topic_id = 95847/*!*/;
# at 3373
…

To get the user, you'll need to set up triggers on the tables and use those triggers to store an audit log in another table.

If you need to all queries—selects included—there is also the general query log but that is not normally on due to performance impacts and disk requirements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文