Trimming a table takes a lot of time, is this normal?

I am using truncate table table_name; on a table with about 1 million lines, but it takes too much time, works from the last 3 hours.

This is normal? Can you suggest another way to remove all rows from the table, which could be faster?

+7
mysql
source share
4 answers

Truncation does not work in some cases, for example,

when you have an index type of things and some foreign key constraints

The simple way I suggest

RENAME TABLE table_name TO t1; CREATE TABLE table_name LIKE t1; DROP TABLE t1; 

or you can also use DELETE FROM table_name;

+30
source share

I believe that a deadlock occurs during query execution, so it’s better to kill it.

I used to delete a lot of data by deleting a small chunk in one request (10k works fine).

So you can fix some script that will do this for you

+1
source share

I just sat down forever (more than 6 minutes) and then I canceled it. Or so I thought. In fact, this step took much less than a second, and I canceled the action of the second LATER step - the Action Output window did not update.

0
source share

It is also recommended that you try to restart the MySQL service or the entire system once if none of the above solutions work.

0
source share

All Articles