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

不执行SQL查询,重启后可以恢复,数据库是阿里云MySQL5.6 #6259

Closed
LeftH0ok opened this issue Apr 22, 2023 · 4 comments
Closed
Assignees
Labels

Comments

@LeftH0ok
Copy link

GORM Playground Link

func GetInstance() *gorm.DB {
host := viper.GetString("mysql.default.hostname")
user := viper.GetString("mysql.default.username")
port := viper.GetString("mysql.default.port")
pass := viper.GetString("mysql.default.password")
dbname := viper.GetString("mysql.default.database")
prefix := viper.GetString("mysql.default.prefix")

once.Do(func() {
	if db == nil {
		var err error
		dsn := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8mb4", user, pass, host, port, dbname)

		db, err = gorm.Open(mysql.Open(dsn), &gorm.Config{
			NamingStrategy: schema.NamingStrategy{
				TablePrefix:   prefix, // table name prefix, table for `User` would be `t_users`
				SingularTable: true,   // use singular table name, table for `User` would be `user` with this option enabled
				//NameReplacer: strings.NewReplacer("CID", "Cid"), // use name replacer to change struct/field name before convert it to db name
			},
			//Logger: logger.Default.LogMode(logger.Info),
			Logger: logger.New(Writer{}, logger.Config{
				SlowThreshold: 0,
				//Colorful:                  true,
				IgnoreRecordNotFoundError: false,
				LogLevel:                  logger.Info,
			}),
		})
		if err != nil {
			fmt.Println(dsn)
			panic(err)
		}
	}
})

sqlDB, _ := db.DB()
sqlDB.SetMaxIdleConns(10)
sqlDB.SetMaxOpenConns(100)

return db

}

func Orm(ctx *gin.Context) {
orm := gormx.GetInstance()

d, _ := orm.DB()
stats := d.Stats()
err := d.Ping()

log.Printf("ping err: %#v, stats: %#v", err, stats)

}

https://go.dev/play/p/-MKUWeDBml7

Description

可以ping以及观测stats状态,但是不执行sql

2023/04/22 20:15:35 ping err: , stats: sql.DBStats{MaxOpenConnections:100, OpenConnections:2, InUse:1, Idle:1, WaitCount:0, WaitDuration:0, MaxIdleClosed:0, MaxIdleTimeClosed:0, MaxLifetimeClosed:0}
2023/04/22 20:16:38 ping err: , stats: sql.DBStats{MaxOpenConnections:100, OpenConnections:2, InUse:1, Idle:1, WaitCount:0, WaitDuration:0, MaxIdleClosed:0, MaxIdleTimeClosed:0, MaxLifetimeClosed:0}
2023/04/22 20:16:41 ping err: , stats: sql.DBStats{MaxOpenConnections:100, OpenConnections:2, InUse:1, Idle:1, WaitCount:0, WaitDuration:0, MaxIdleClosed:0, MaxIdleTimeClosed:0, MaxLifetimeClosed:0}
2023/04/22 20:16:41 ping err: , stats: sql.DBStats{MaxOpenConnections:100, OpenConnections:2, InUse:1, Idle:1, WaitCount:0, WaitDuration:0, MaxIdleClosed:0, MaxIdleTimeClosed:0, MaxLifetimeClosed:0}
2023/04/22 20:16:42 ping err: , stats: sql.DBStats{MaxOpenConnections:100, OpenConnections:2, InUse:1, Idle:1, WaitCount:0, WaitDuration:0, MaxIdleClosed:0, MaxIdleTimeClosed:0, MaxLifetimeClosed:0}
2023/04/22 20:16:42 ping err: , stats: sql.DBStats{MaxOpenConnections:100, OpenConnections:2, InUse:1, Idle:1, WaitCount:0, WaitDuration:0, MaxIdleClosed:0, MaxIdleTimeClosed:0, MaxLifetimeClosed:0}
2023/04/22 20:16:43 ping err: , stats: sql.DBStats{MaxOpenConnections:100, OpenConnections:2, InUse:1, Idle:1, WaitCount:0, WaitDuration:0, MaxIdleClosed:0, MaxIdleTimeClosed:0, MaxLifetimeClosed:0}

@github-actions github-actions bot added the type:missing reproduction steps missing reproduction steps label Apr 22, 2023
@LeftH0ok
Copy link
Author

@jinzhu

@LeftH0ok
Copy link
Author

@sunfmin

@github-actions
Copy link

The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.ioSearch Before Asking

@a631807682
Copy link
Member

duplicated of #6258

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

No branches or pull requests

3 participants