title: write lock all tables in mysql for a moment
body: <p>I need to perform some scripted actions, which may take a while (like maybe a minute). At the beginning of these actions, I take some measures from the MySQL DB and it's important that they do not change until the actions are done. The DB has dozens of tables since it belongs to a quite old fashioned but huge CMS, and the CMS users have a dozen options to modify it.</p>
  
  <p><em>I do not even want to change anything in the time my scripts runs in the DB myself, it just shall be frozen. It's not a Dump or Update. But tables should be kept open for reading for everyone, to prevent visitors of the connected homepage from getting errors.</em></p>
  
  <p>If the database altering actions, which may be performed by other CMS users in the meantime would be triggered after the DB is unlocked again, it would be perfect, but if they fail, I would not mind.</p>
  
  <p>So I thought at the beginning of the script I lock the tables down with</p>
  
  <pre><code>lock first_table write;
  lock second_table write;
  ...
  </code></pre>
  
  <p>And after I do</p>
  
  <pre><code>unlock tables
  </code></pre>
  
  <p>I think that should do exactly what I want. <strong>But can I archive this for all tables of the db without naming them explicitly, to make this more futureproof?</strong> </p>
  
  <p>This does not work for sure:</p>
  
  <pre><code>lock tables (select TABLE_NAME from information_schema.tables
  where table_schema='whatever') write;
  </code></pre>
  
  <p>Another question would be, if someone can answer this on the fly, if I would have to perfom the lock/unlock with another MYSQL user than the one used by the CMS. If I understood this right, then yes.</p>