Set MySQL to Read-Only

For a backup server which we may want to run as read-only for short maintenance periods the following may be useful.
Method 1: Global read_only
Login to MySQL and set the read_only setting to true:

mysql -u root -p
set GLOBAL read_only = true;

To unset this run:

set GLOBAL read_only = false;

Method 2: Read Lock
Another method which will queue queries while the tables are locked and then run them when the tables have been unlocked involves:

FLUSH TABLES WITH READ LOCK;

To revert back use:

UNLOCK TABLES;

Leave a Reply

  • (will not be published)

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">