// NewDBConnection returns a new DBConnection based on the ConnParams // and will use the provided stats to collect timing. func NewDBConnection(info *sqldb.ConnParams, mysqlStats *stats.Timings) (*DBConnection, error) { params, err := dbconfigs.MysqlParams(info) if err != nil { return nil, err } c, err := sqldb.Connect(params) return &DBConnection{c, mysqlStats}, err }
// Connect connects to a db server func (dc *DBClient) Connect() error { params, err := dbconfigs.MysqlParams(dc.dbConfig) if err != nil { return err } dc.dbConn, err = sqldb.Connect(params) if err != nil { return fmt.Errorf("error in connecting to mysql db, err %v", err) } return nil }
// connectForReplication create a MySQL connection ready to use for replication. func (mysqld *Mysqld) connectForReplication() (sqldb.Conn, error) { params, err := dbconfigs.MysqlParams(mysqld.dba) if err != nil { return nil, err } conn, err := sqldb.Connect(params) if err != nil { return nil, err } // Tell the server that we understand the format of events // that will be used if binlog_checksum is enabled on the server. if _, err := conn.ExecuteFetch("SET @master_binlog_checksum=@@global.binlog_checksum", 0, false); err != nil { return nil, fmt.Errorf("failed to set @master_binlog_checksum=@@global.binlog_checksum: %v", err) } return conn, nil }
// NewSlaveConnection creates a new slave connection to the mysqld instance. // It uses a pools.IDPool to ensure that the server IDs used to connect are // unique within this process. This is done with the assumptions that: // // 1) No other processes are making fake slave connections to our mysqld. // 2) No real slave servers will have IDs in the range 1-N where N is the peak // number of concurrent fake slave connections we will ever make. func (mysqld *Mysqld) NewSlaveConnection() (*SlaveConnection, error) { params, err := dbconfigs.MysqlParams(mysqld.dba) if err != nil { return nil, err } conn, err := sqldb.Connect(params) if err != nil { return nil, err } sc := &SlaveConnection{ Conn: conn, mysqld: mysqld, slaveID: slaveIDPool.Get(), } log.Infof("new slave connection: slaveID=%d", sc.slaveID) return sc, nil }