I have schema migration code that uses a database table (MIGRATIONS) to record what migrations have been run on the schema. When it comes to running new migrations into the schema, the code locks the table, so no other instance in the cluster can also perform migrations, checks what migrations need to be run, and runs them. I lock the MIGRATIONS table using this sql:
lock tables migration_log write;
If one of my migrations ends up creating a table, I get this error:
Table 'tbl_name' was not locked with LOCK TABLES
I read that once you issue a LOCK TABLES statement you can only deal with the tables mentioned in that statement.
So, bottom line: How can I lock one table in mysql, while also creating another?
Failing that, can you suggest another approach to achieve what I am trying to achieve?
Do you really need to lock whole table? Maybe just row-locking is sufficient?
http://lists.mysql.com/cluster/4467