Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Truncating table does not make the mysql file smaller

I truncated several huge tables, but the mysql file and database appears to remain at the same size.

Does truncate table delete the data from mysql as well?

like image 595
meow Avatar asked May 20 '10 01:05

meow


People also ask

What happens when you TRUNCATE a table MySQL?

TRUNCATE TABLE empties a table completely. It requires the DROP privilege. Logically, TRUNCATE TABLE is similar to a DELETE statement that deletes all rows, or a sequence of DROP TABLE and CREATE TABLE statements. To achieve high performance, TRUNCATE TABLE bypasses the DML method of deleting data.

Does TRUNCATE table release space in MySQL?

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.

What happens when a table is truncated?

TRUNCATE TABLE removes all rows from a table, but the table structure and its columns, constraints, indexes, and so on remain. To remove the table definition in addition to its data, use the DROP TABLE statement.

Does TRUNCATE table Release space?

No, truncate doesn't release anything. The reason why truncate is quick is because it simply moves the High Water Mark in the table, effectively back to the start of the table so that it appears there is no longer any data in it.


2 Answers

When a large table is deleted or truncated InnoDB storage engine for MySQL will leave the empty space, and use it for subsequent insertion of new row versions.

There are ways to shrink database. Check Re: how to shrink a MySQL database

like image 105
volody Avatar answered Sep 24 '22 18:09

volody


In Version 5.1.55 size was not reduced after Truncate , even with innodb_file_per_table='ON'. So need to DROP and then CREATE the table and then Size was reduced.

like image 30
Gopal Avatar answered Sep 25 '22 18:09

Gopal