mysql shutdown and kill
--mysqladmin shutdown
If you execute mysqladmin shutdown when connecting to a local server using a Unix socket file, mysqladminwaits until the server's process ID file has been removed, to ensure that the server has stopped properly.
KILL
Syntax
KILL [CONNECTION | QUERY] thread_id
Each connection to mysqld runs in a separate thread. You can see which threads are running with the SHOW PROCESSLIST
statement and kill a thread with the KILL
statement.thread_id
KILL
permits an optional CONNECTION
or QUERY
modifier:
-
KILL CONNECTION
is the same asKILL
with no modifier: It terminates the connection associated with the giventhread_id
. -
KILL QUERY
terminates the statement that 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.
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:
-
In
SELECT
,ORDER BY
andGROUP 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
, 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
orDELETE
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. Note that if you are not using transactions, the changes are not rolled back. -
GET_LOCK()
aborts and returnsNULL
. -
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
orOPTIMIZE TABLE
operation on aMyISAM
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).
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
2013-06-20 范型练习
2013-06-20 Java范型
2013-06-20 Hadoop之HelloWorld
2013-06-20 could only be replicated to 0 nodes, instead of 1
2013-06-20 ssh相关问题