When we need to set the database as read-only on the fly (such as rebuild MySQL replication purpose) and we will use one of the following scripts. I have tested and turns out, we need to run both commands to ensure that there is no writing input to the database.
To Set a database to read-only mode in Mysql:
FLUSH TABLES WITH READ LOCK;
SET GLOBAL read_only = 1;
To Set the database back to Read+Write mode:
SET GLOBAL read_only = 0;