MySQL Locking

15 September 2010
After experimenting a bit with MySQL locking today, I thought I’d make a note of what I’d discovered: To create a lock, you need to use: <code>LOCK TABLES table1 [READ |WRITE], table2 [READ |WRITE]</code> READ is used to stop other people changing the table while you read from it. WRITE is used to stop other people reading the table while you write to it. Once you have issued a LOCK TABLES statement, you will not have access to any tables you didn’t include.
If you find that after rebooting your MySQL slave it stops replicating with the master and you see the “Failed to open the relay log” error in the logs it is probably caused by MySQL putting it’s relay logs in /var/run by default, which gets cleared out on boot. To fix this, you need to change the location MySQL uses for the logging by adding the following line to the [mysqld] section of /etc/my.
Make sure that expire_logs_days is set to ensure that log rotation takes place