MySQL kill操作

2024-06-13 01:41:21
KILL [CONNECTION | QUERY] thread_id

每个与mysqld的连接都在一个独立的线程里运行,您可以使用SHOW PROCESSLIST语句查看哪些线程正在运行,并使用KILL thread_id语句终止一个线程。

KILL允许自选的CONNECTION或QUERY修改符:

·  KILL CONNECTION与不含修改符的KILL一样:它会终止与给定的thread_id有关的连接。

·  KILL QUERY会终止连接当前正在执行的语句,但是会保持连接的原状。

如果您拥有PROCESS权限,则您可以查看所有线程。如果您拥有SUPER权限,您可以终止所有线程和语句。否则,您只能查看和终止您自己的线程和语句。

您也可以使用mysqladmin processlist和mysqladmin kill命令来检查和终止线程。

注释:您不能同时使用KILL和Embedded MySQL Server库,因为内植的服务器只运行主机应用程序的线程。它不能创建任何自身的连接线程。

当您进行一个KILL时,对线程设置一个特有的终止标记。在多数情况下,线程终止可能要花一些时间,这是因为终止标记只会在在特定的间隔被检查:

·  在SELECT, ORDER BY和GROUP BY循环中,在读取一组行后检查标记。如果设置了终止标记,则该语句被放弃。

·  在ALTER TABLE过程中,在每组行从原来的表中被读取前,检查终止标记。如果设置了终止标记,则语句被放弃,临时表被删除。

·  在UPDATE或DELETE运行期间,在每个组读取之后以及每个已更行或已删除的行之后,检查终止标记。如果终止标记被设置,则该语句被放弃。注意,如果您正在使用事务,则变更不会被 回滚。

·  GET_LOCK()会放弃和返回NULL。

·  INSERT DELAYED线程会快速地刷新(插入)它在存储器中的所有的行,然后终止。

·  如果线程在表锁定管理程序中(状态:锁定),则表锁定被快速地放弃。

·  如果在写入调用中,线程正在等待空闲的磁盘空间,则写入被放弃,并伴随"disk full"错误消息。

·  警告:对MyISAM表终止一个REPAIR TABLE或OPTIMIZE TABLE操作会导致出现一个被损坏的没有用的表。对这样的表的任何读取或写入都会失败,直到您再次优化或修复它(不中断)。

下面MySQL5.6的官方说明:

http://dev.mysql.com/doc/refman/5.6/en/kill.html

KILL [CONNECTION | QUERY] processlist_id

Each connection to mysqld runs in a separate thread. You can kill a thread with the KILL processlist_id statement.

Thread processlist identifiers can be determined from the ID column of the INFORMATION_SCHEMA.PROCESSLIST table, the Id column of SHOW PROCESSLIST output, and the PROCESSLIST_ID column of the Performance Schema threads table. The value for the current thread is returned by the CONNECTION_ID() function.

KILL permits an optional CONNECTION or QUERY modifier:

KILL CONNECTION is the same as KILL with no modifier: It terminates the connection associated with the given processlist_id, after terminating any statement the connection is executing.

KILL QUERY terminates the statement the connection is currently executing, but leaves the connection itself intact.

If you have the PROCESS privilege, you can see all threads. If you have the SUPER privilege, you can kill all threads and statements. Otherwise, you can see and kill only your own threads and statements.

You can also use the mysqladmin processlist and mysqladmin kill commands to examine and kill threads.

Note

You cannot use KILL with the Embedded MySQL Server library because the embedded server merely runs inside the threads of the host application. It does not create any connection threads of its own.

When you use KILL, a thread-specific kill flag is set for the thread. In most cases, it might take some time for the thread to die because the kill flag is checked only at specific intervals:

During SELECT operations, for ORDER BY and GROUP BY loops, the flag is checked after reading a block of rows. If the kill flag is set, the statement is aborted.

During ALTER TABLE operations, the kill flag is checked before each block of rows are read from the original table. If the kill flag was set, the statement is aborted and the temporary table is deleted.

During UPDATE or DELETE operations, the kill flag is checked after each block read and after each updated or deleted row. If the kill flag is set, the statement is aborted. If you are not using transactions, the changes are not rolled back.

GET_LOCK() aborts and returns NULL.

An INSERT DELAYED thread quickly flushes (inserts) all rows it has in memory and then terminates.

If the thread is in the table lock handler (state: Locked), the table lock is quickly aborted.

If the thread is waiting for free disk space in a write call, the write is aborted with a “disk full” error message.

Warning

Killing a REPAIR TABLE or OPTIMIZE TABLE operation on a MyISAM table results in a table that is corrupted and unusable. Any reads or writes to such a table fail until you optimize or repair it again (without interruption).

转载于:https://blog.51cto.com/huangfuff/1613652

MySQL kill操作相关推荐

  1. MySQL实战篇-MySQL kill进程后出现killed

    问题描述 拷贝一个大表的表数据的时候,等待时间太久,就在前台通过CTRL+C的方式停掉了. mysql> create table fact_sale_new as select * from ...

  2. MySQL kill进程后出现killed

    文章目录 一.问题描述 二.解决方案 三.额外的一个报错 四.启用innodb_force_recovery=3 参考: 一.问题描述 拷贝一个大表的表数据的时候,等待时间太久,就在前台通过CTRL+ ...

  3. mysql kill 无效_mysql kill不生效?

    生产环境出现过多次mysql hang住,写操作的sql堵住的情况,这个时候使用kill来kill所有的连接,但是大部分时候连接kill 后处于freeing item状态,kill在这种场景下基本无 ...

  4. mysql kill 指令_MySQL kill指令使用指南

    KILL [CONNECTION | QUERY] processlist_id 在Mysql中每个连接都是单独线程运行,可以使用语句 KILL processlist_id statement.来终 ...

  5. mysql kill 指令,SHOW PROCESSLIST指令与KILL指令

    功能版本说明当 DRDS 版本号小于 5.1.28-1408022 时,DRDS 仅支持物理连接的 SHOW PROCESSLIST 与 KILL 功能,请参见老版本 SHOW PROCESSLIST ...

  6. mysql dba系统学习(19)配置mysql+lvs+keeplived实现Mysql读操作的负载均衡

    配置mysql+lvs+keeplived实现Mysql读操作的负载均衡 环境: test1192.168.46.131master test2192.168.46.130slave备份test库 t ...

  7. mysql 命令行访问_Mysql 命令行模式访问操作mysql数据库操作

    使用环境 在cmd模式下输入 mysql --version (查看mysql安装的版本). 完整的命令可以通过mysql --help来获取. 本测试使用的Mysql版本是mysql5, 本测试使用 ...

  8. Linux中mysql的操作

    一.mysql服务操作 二.数据库操作 三.数据表操作 四.修改表结构 五.数据备份和恢复 六.卸载数据库 转载于:https://www.cnblogs.com/clover-siyecao/p/5 ...

  9. MySQL—02—MySQL的操作

    一.MySQL的操作 1.  创建与删除数据库 1.1使用命令创建数据库 创建一个 test 的数据库,并查看该数据库,以及该数据库的编码. 创建数据库: create database test d ...

最新文章

  1. 【Groovy】编译时元编程 ( 编译时元编程引入 | 声明需要编译时处理的类 | 分析 Groovy 类的 AST 语法树 )
  2. sklearn常用模块
  3. 原生android 全面屏,谷歌全面屏手机曝光!谷歌pixel2,安卓8.0+骁龙836!
  4. bash: shasum: command not found
  5. 【思维】Kenken Race
  6. PresentViewController切换界面
  7. Redisson实现分布式锁
  8. 前端面试之你可能会遇到的编程题(1)
  9. K8s(二):130 道 K8s/Docker 配套练习题,学+练结合,一次吃透
  10. 关于西门子STEP7 在Windows10安装的一些心得
  11. win10离线安装.NetFrameWork3.5出现0x800F081F解决办法。
  12. 隔离模块介绍-隔离电源模块
  13. 全网最全面的GitHub使用教程
  14. 笔记:Linux系统调用在文件中的分布情况
  15. 防火墙添加ip白名单_如何给防火墙加白名单 防火墙添加ip白名单
  16. Android获取系统邮件账号
  17. Nachos实验实现线程id、限制线程数和更改调度算法(按优先级调度)
  18. 一个人如果不结婚也无儿无女无兄弟姐妹,虽然可以自由自在一辈子,但老了怎么办?
  19. XCODe运行yueyu设置
  20. 专访2017未来科学大奖“数学与计算机科学”奖得主许晨阳教授

热门文章

  1. more effective C++
  2. NAT的经典配置实例
  3. Windows系统安全模式妙用全接触
  4. 基于用例的工作量估计
  5. 公司6:JrVue重用布局
  6. Oracle查询数据库中所有表的记录数
  7. 当你从事不喜欢的事怎么办
  8. linux网卡设置详解,史上最详细的Linux网卡ifcfg-eth0配置详解
  9. centos7 校正linux系统时间_基于centos7系统部署NTP服务及配置时间定时同步
  10. link 和 @import 的区别