On the slave, SET GLOBAL READ_ONLY = 1;
. Then, users with write privileges will not be able to write to the slave... any attempt to change data will be met with an error that says, essentially, "the slave is running in read-only mode" and the writes will be denied.
Users with the SUPER
privilege will retain write access (but they are immune to init_connect
anyway) and the replication threads will not be affected.
For the users who don't need access to the master, drop their accounts from the master and add them directly to the slave. This does not cause a problem as long as you don't subsequently add the same user back to the master without dropping them from the slave first.
There's not a more elegant way to do what you're attempting, if the client is trying to reconnect on its own. You're doing a clean disconnect. The only alternative I can think of for you to try, instead of killing the connection, might be putting a ROLLBACK RELEASE;
in the procedure, which also drops the client connection... though I suspect the client will still try to reconnect, if the disconnect is unexpected by the client.
https://dev.mysql.com/doc/refman/5.6/en/server-system-variables.html#sysvar_read_only
Incidentally, in the current implementation, a simpler way to distinguish between master and slave would be to check the value of the @@SERVER_ID
or @@HOSTNAME
variables.