-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Issue description
Executing SET sql_log_bin = 0
on a *sql.Tx should be successful, but Error 1694: Cannot modify @@session.sql_log_bin inside a transaction
is returned.
Example code
func commitPrepare(db *sql.DB) (*sql.Tx, error) {
tx, err := db.Begin()
if nil != err {
return nil, errors.Trace(err)
}
// Disable sql binlog record
_, err = tx.Exec("SET sql_log_bin = 0")
if nil != err {
tx.Rollback()
return nil, errors.Trace(err)
}
return tx, nil
}
Error log
Error 1694: Cannot modify @@session.sql_log_bin inside a transaction
Configuration
Driver version (or git SHA): current
Go version: go1.9.4 windows/amd64
Server version: MySQL 5.6
Server OS: CentOS 7.2.1511
Description
As we known, sql.DB caches all used DB connections in a pool, every normal query/exec will create/select one connection in the pool. So if we want to set the session flag, we must get the connection before executing any command, the *sql.Tx pointer holds a DB connection so we can set the command and every commands following will use the same DB connection.
But the *sql.Tx returned by sql.Begin function also executed the begin command, and the session command i want to execute can't execute in a transaction.
Is there any solution to solve this problem ?