Anda tidak dapat memotong tabel yang dikunci untuk menulis. Ini karena "truncate" berarti "hancurkan tabel, dan buat ulang tabel baru dengan skema yang sama."
Namun Anda dapat, kosong meja. Alih-alih TRUNCATE TABLE asin_one_time_only
gunakan DELETE FROM asin_one_time_only
. Perhatikan bahwa ini tidak akan mengatur ulang penomoran kenaikan otomatis. Jika Anda ingin mengatur ulang juga, gunakan ALTER TABLE asin_one_time_only auto_increment=1
Saya sarankan melakukan ini:
LOCK TABLES asin_one_time_only READ;
SELECT asin FROM asin_one_time_only;
-- minimize the possibility of someone writing to the table in-between
-- an "UNLOCK TABLES" and a "LOCK TABLES" by just issuing a new LOCK TABLES
-- I am not 100% sure that MySQL will do this atomically, so there is a
-- possibility that you may delete a row that was not read.
-- If this is unacceptable, then use a "LOCK TABLES asin_one_time_only WRITE"
-- from the very beginning.
LOCK TABLES asin_one_time_only WRITE;
DELETE FROM asin_one_time_only;
ALTER TABLE asin_one_time_only auto_increment=1;
UNLOCK TABLES;