跑truncate table,4億條數據會不會造成長時間鎖表呢?有什么更好的方法嗎? 最好是create新表,然后交叉rename對調,再drop/truncate table或其他方式清除數據。 一、可操作步驟: 創建新的 tmp 表,正式表與tmp表表名交換(注意在一個SQL里完成,並鎖表) 對 tmp 表創建硬鏈接 ln tmp.ibd tmp.ibd.hdlk mysql中刪除表tmp(truncate / drop 都行) 然后找個業務不繁忙的時間刪除數據文件或者用coreutils 的truncate慢慢搞。 二、關於truncate table,官檔解釋: Logically, TRUNCATE TABLE is similar to a DELETE statement that deletes all rows, or a sequence of DROP TABLE and CREATE TABLE statements. When a table is truncated, it is dropped and re-created in a new .ibd file, and the freed space is returned to the operating system.