创建索引失败,表一直查询不了
是因为锁表了
1200条数据数据的表,创建索引2分钟都没有弄完。[2025-09-18 14:07:54] exam> CREATE INDEX idx_sud_userid_depidON sys_user_depart (user_id, dep_id)COMMENT '用户-部门关联表:优化user_id与dep_id的联合查询,提升主查询驱动表效率' [2025-09-18 14:09:53] completed in 1 m 59 s 162 ms [2025-09-18 14:09:53] Error unmarshaling return header; nested exception is: [2025-09-18 14:09:53] java.net.SocketException: Connection reset
后面select * from sys_user_depart 两三分钟都不行。
查询进程
SELECTid 线程ID,time 执行时间,state 线程状态, -- 若显示"Waiting for table metadata lock",说明被其他线程阻塞info 执行语句, -- 可能是之前中断的索引创建语句或未提交的事务user 操作用户,host 来源地址,db 数据库名,command 命令类型
FROM
information_schema.processlist
WHERE
db = 'huiren_exam_dev' -- 替换为你的数据库名
AND (info LIKE '%sys_user_depart%' -- 替换成你的表名
OR state LIKE '%metadata lock%');
找到数字最大的那几个进程杀掉就可以了。
-- 选择执行时间最长的3个线程(5017、5058、5026,均超过15000秒)
KILL 5017;
KILL 5058;
KILL 5026;
额外说一下:
select * from information_schema.processlist,可以缩写成show proccesslist。
mysql中information_schema中的表都可以用show关键字快速查表。
以后遇到什么问题都去看MySQL自带的information_schema的表找原因