Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql size of tables is not immediately updated after delete

Tags:

sql

mysql

I have a database which holds Logentries of several applications. Now I have written a bash-Script which should delete the oldest day when a size limit is exceeded. I have a loop which deletes day per day until the acctual size is smaller then the limit. But after the delete-statements the size of the table is not properly updated.

I used this Sql Statement

'SELECT round(((data_length + index_length)), 0) "Size in Bytes" FROM information_schema.TABLES WHERE table_schema = "Log" AND table_name = "Log";'

to determine the acctual table size. How can I force MySql to recaclulate this size immediately after a delete command?

like image 368
user2071938 Avatar asked Sep 02 '14 12:09

user2071938


People also ask

How do you refresh a table in MySQL?

To access the Refresh from Database dialog box, right-click an object in MySQL Metadata Explorer and click Refresh from Database.

Does MySQL update automatically?

Yes, Views automatically update in MySQL; including, but not limited to: Changing table structures. Insert/Update/Delete procedures on Tables.

How long does MySQL update take?

RDS for MariaDB, RDS for MySQL, and RDS for PostgreSQL DB instances occasionally require operating system updates. Amazon RDS upgrades the operating system to a newer version to improve database performance and customers' overall security posture. Typically, the updates take about 10 minutes.

How do I completely delete a table in MySQL?

To permanently remove a table, enter the following statement within the MySQL shell: DROP TABLE table1; Replace table1 with the name of the table you want to delete. The output confirms that the table has been removed.


1 Answers

Run

 OPTIMIZE TABLE Log

After deleting. This will update the index statistics (and free all unused disk-space btw).

like image 123
Benvorth Avatar answered Sep 27 '22 17:09

Benvorth