Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
guoweikuang opened this issue Sep 30, 2021 · 0 comments
Assignees

Comments

@guoweikuang
Copy link

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))

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants