Neo
Neo

Reputation: 13891

Sql : Side effects of creating/deleting databases and tables on the fly

I need to simulate sql by creating a wrapper over mysql(customer requirement :P), and hence my application requires to create/drop tables(and possibly databases) during runtime.

The frequency of such create/drop operations will not be very high. I'm not a database expert, but I believe that such operations could lead to some side-effects over long term.

Is it advisable to do go ahead with these creation/deletion of databases and what are the possible complications I can run into?

Upvotes: 0

Views: 271

Answers (1)

RolandoMySQLDBA
RolandoMySQLDBA

Reputation: 44343

This is only a problem under two scenarios

SCENARIO #1

For InnoDB tables, the innodb buffer pool should be optimally set to the sum of all data pags and index pages that make up InnoDB tables.

Even worse can be that innodb_file_per_table is disabled (default)

This will produce a file called /var/lib/mysql/ibdata1 which can grow and never shrink. This is true no matter how many times you drop and create databases.

If one forgets to make the necessary changes in /etc/my.cnf, this could also expose innodb buffer pool to under-utilization until the data fills back up.

Changes to make for InnoDB are straightforward.

Run this query

SELECT CONCAT(KeyBuf,'M') BufferPoolSetting FROM (SELECT CEILING(SumInnoDB/POWER(1024,2)) KeyBuf FROM (SELECT SUM(data_length+index_length) SumInnoDB FROM information_schema.tables WHERE engine='InnoDB' and table_schema NOT IN ('information_schema','mysql')) A) AA;

The output of this query should be used as the innodb_buffer_pool_size in /etc/my.cnf just before you drop all databases and create new ones.

SCENARIO #2

For MyISAM tables, the key buffer should be optimally set to the sum of all .MYI files.

If one forgets to make the necessary changes in /etc/my.cnf, this could also expose MyISAM key cache (key buffer) to under-utilization until the data fills back up.

Changes to make for MyISAM are straightforward.

Run this query

SELECT CONCAT(KeyBuf,'M') KeyBufferSetting FROM (SELECT CEILING(SumIndexes/POWER(1024,2)) KeyBuf FROM (SELECT SUM(index_length) SumIndexes FROM information_schema.tables WHERE engine='MyISAM' and table_schema NOT IN ('information_schema','mysql')) A) AA;

The output of this query should be used as the key_buffer_size in /etc/my.cnf just before you drop all databases and create new ones.

Upvotes: 1

Related Questions