Skip to content

An error occurred after the mysql active/standby switch:The MySQL server is running with the --read-only option so it cannot execute this statement #49

@guoweikuang

Description

@guoweikuang

GORM Playground Link

go-gorm/playground#1

Description

1、Stop the main library directly, and then switch between main and standby
2、log print: The MySQL server is running with the --read-only option so it cannot execute this statement
3、The read_only parameter confirms that it has been set to 0
4、 mysql 5.6
dsn: master
db2Dsn: slave
`

           err = db.Use(dbresolver.Register(dbresolver.Config{
		Replicas: []gorm.Dialector{mysql.Open(db2Dsn), mysql.Open(dsn)},
		// sources/replicas 负载均衡策略, 默认随机
		// todo - 比例随机均匀, 读主 读从. 如需调整,需要自定义 Policy
		Policy: dbresolver.RandomPolicy{},
	}, tabs...).
		SetMaxOpenConns(slaveCnf.MaxOpenCons).
		SetMaxIdleConns(slaveCnf.MaxIdleCons).
		SetConnMaxLifetime(time.Duration(slaveCnf.MaxLifetime) * time.Second))

`

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions