If you do the following:
- connect to mysql
- perform
SET sql_log_bin=0;
- execute the query (INSERT, UPDATE, or DELETE)
- close the DB connection
then there is no need to SET sql_log_bin=1; afterwards
As an alternative, you may want to try this:
- open a second DB Connection
- set the
SET sql_log_bin=0; (this done once in the lifetime of the second DB connection)
- keep that second DB Connection open
- use only this second DB connection for writes that are not be recorded in the binary logs
Give it a Try !!!
UPDATE 2012-01-06 14:55 EDT
Here is something interesting you may not have realized: Only those SUPER privilege can set one's own session to disable binary logging.
According to the MySQL Documentation on SUPER:
The SUPER privilege enables an account to use CHANGE MASTER TO, KILL
or mysqladmin kill to kill threads belonging to other accounts (you
can always kill your own threads), PURGE BINARY LOGS, configuration
changes using SET GLOBAL to modify global system variables, the
mysqladmin debug command, enabling or disabling logging, performing
updates even if the read_only system variable is enabled, starting and
stopping replication on slave servers, specification of any account in
the DEFINER attribute of stored programs and views, and enables you to
connect (once) even if the connection limit controlled by the
max_connections system variable is reached.
To create or alter stored functions if binary logging is enabled, you
may also need the SUPER privilege, as described in Section 18.7,
“Binary Logging of Stored Programs”.
Having users with SUPER privilege gives them additional fire power that they may not need or may want to abuse.