I have a problem with OPTIMIZE TABLE query with one of my InnoDB database tables. I have a database that contains several different tables and data is constantly accumulating in these tables. However I have my own automatic services that I use for deleting older rows from these tables.

After deleting old rows with my service I also use optimize table command to free up disk space. (innodb_file_per_table = 1)

Everything has been working well (I have used these services successfully with other tables (size 100-200MB) but now I have faced a problem with one larger table (size 900-1000MB).

Deleting data with that larger table is working fine, but when I try to use OPTIMIZE TABLE query I get error:

Error on mysql optimizing log_events table: Fatal error encountered during command execution. at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior) at MySql.Data.MySqlClient.MySqlCommand.ExecuteNonQuery() at CleanTablesService.Service1.siivoaTaulut(Object& yhteys) in c:\users\green automation\documents\visual studio 2015\Projects\CleanTablesService\CleanTablesService\Service1.vb:line 127

I assume that this has something to do with some buffer_size or something like that? I'm able to execute this exactly same query successfully with MySQL Workbench but when executing query on my service it throws this error.

So is there some value in my.ini file that I need to adjust so that I can make it work or is there some other method that I should use for optimizing table size (releasing disk space after I have deleted old rows)?

EDIT: I added some more logging to my service and I noticed that this Fatal error is raised 30s after executing OPTIMIZE TABLE. In MySQL Workbench execution of this same operation takes 67.110s so probably problem is that for some reason MySQL is killing execution in the middle of the process after 30s? However I cannot find any parameter from my MySQL Settings file my.ini that would affect this 30s timeout.

有帮助吗?

解决方案

Ok I feel really stupid now... Problem had nothing to do with MySQL Server settings etc. Problem was that in my service (that is communicating with MySQL) I'm using MySqlCommand Object (Service is coded using VB NET). This MySqlCommand object has a parameter CommandTimeout and its default value is 30. So that was the reason why executions longer than 30s caused timeout that throws fatal error.. So now I'm setting this parameter large enough in my VB NET code before executing command and everything is working as planned!

许可以下: CC-BY-SA归因
不隶属于 dba.stackexchange
scroll top