如何停止正在运行的 mysql 查询

发布于 2024-08-18 01:18:04 字数 295 浏览 5 评论 0原文

如何以编程方式停止正在运行的 mysql 查询?

我面临的问题是查询是使用用户提供的数据构建的,并且有时可能需要很长时间才能执行(大型表 15 - 3000 万行)。我想为用户提供一个取消选项,但不知道如何停止当前正在执行的 mysql 查询。

该应用程序是一个 Java applet-servlet:用户在 applet 中指定条件,该条件将传递到 servlet,在 servlet 中创建处理程序类来处理请求。这个处理程序类是独立的重新连接-查询-断开到mysql。

在这种情况下,如何取消正在运行的 mysql 查询?

How do I stop a running mysql query programmatically?

The problem I'm facing is that a query is constructed using user supplied data, and may occasionally take a very long time to execute (large tables 15 - 30 million rows). I want to offer the user a cancel-option, but don't know how to stop the currently executing mysql-query.

The application is a Java applet-servlet: the user specify criteria in the applet which is passed to the servlet where a handler-class is created to handle the request. This handler-class is self-contained re connect - query - disconnect to mysql.

Given this scenario, how do I cancel a running mysql-query?

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

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

发布评论

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

评论(3

夏末染殇 2024-08-25 01:18:04
SHOW PROCESSLIST;
KILL <thread_to_be_killed>;

有关其他详细信息,请参阅文档

显示进程列表

终止正在运行的线程

SHOW PROCESSLIST;
KILL <thread_to_be_killed>;

Refer to the documentation for additional details

Show The Process List

Kill A Running Thread

不乱于心 2024-08-25 01:18:04

需要单独的 JDBC 连接,这意味着您必须创建一个新的数据库处理程序实例。执行 SHOW PROCESSLIST 语句,然后循环查看结果并为找到的每个线程 ID 执行 KILL 语句给定的用户。

我认为做到这一点的唯一可靠方法是每个用户都必须以不同的用户名登录到数据库,然后获取该用户的所有线程 ID 并杀死他们的所有线程。

A separate JDBC connection is required, which means you'll have to create a new database handler instance. Execute SHOW PROCESSLIST statement and then loop through the results and execute a KILL statement for each thread id found for the given user.

The only reliable way I can think to do this is every user would have to log in to the database under a different user name, then get all thread id's for that user and kill all their threads.

忆依然 2024-08-25 01:18:04

您可以通过 MySQL 提供的标准库发出 MySQL 特定命令并运行 KILL查询。也许最好列出进程并找出需要首先终止的线程。

不过,根据您的应用程序,这可能会产生安全问题(因为您需要向连接的应用程序用户授予更多权限)。

You can issue MySQL specific commands through the standard libraries provided by MySQL and run KILL QUERY. Possibly it's best listing the processes and figuring out which thread you need to kill first.

Depending on your application this might create a security issue though (since you need to give more privileges to the connecting application user).

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