Mysql – Does MySQL allows incoming queries while altering a table

alter-tableinnodbMySQLmysql-innodb-cluster

I'm adding a new column to an existing table say ABC with the following query,

ALTER TABLE ABC add column STATUS int(10) NOT NULL

This is done in master, slave and secondary slaves. Meanwhile, while altering the existing table (which does not contain any data) – other databases (other schemas and tables) were queried – both in master and slave databases.

After altering column in the table ABC has been completed I could see slowness in many app servers and few got killed stating "You have reached your max limit to DB Connections" and you could make no more DB connections and the app server got killed.

I also run a jsp in one of my servers – the thread gets hanged (stopped after making connection to one of secondary slave) in the mean time. I'm a no DB expert. I'm a novice MySQL learner and do not have any prior experience I do not know how to debug further.

I suspect whether my MySQL servers (either master or slave) does not accept any incoming connections while altering a table and once the table alteration gets completed it accepts the queued up requests and process them one by one.

Since the connections got queued up the app servers – which are waiting for previous query response – couldn't make any more requests. Can someone shed some insights to debug

  • on db connection getting exhausted and

  • the thread which invoked a jsp never ends (stops where it makes connection to mysql) – this happened during the timestamp when alter table happened.

Best Answer

During a DDL operation (e.g. alter table) MySQL locks only the objects in question - in this case the table.

Other tables and databases remain unaffected and new connections are accepted as usual.

On a slave, the DDL operation can't be executed in parallel, so it will delay the replication by whatever time it takes to execute.

The alter operation can increase the general server load CPU/MEM/IO, which can cause it to run out of resources. This rare (with a server with at least a few cores), and pretty much impossible with an empty table, because the alter takes < 1 sec.

The only way a DDL directly affects other connections is if they use the table/s which are modified.