英文:
How to reset the connection status getting from go database/sql pool?
问题
如果我执行 db.exec("set time_zone = '+00:00'")
,执行该 SQL 的连接的状态 time_zone 将会改变,连接会被放回连接池吗?
如果是这样的话,它会被另一个不知道连接状态已经改变的处理器重用吗?
英文:
If I exec a db.exec("set time_zone = "+00:00"")
,
the status time_zone of connection to exec the SQL will change
and will the connection be put back to the pool?
If so, will it be reused by another processor who doesn't know the status of connection has been changed?
答案1
得分: 1
正确的方法是在连接字符串中设置时区:
sql.Open("mysql", "root@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=true&time_zone=%2B00%3A00")
请注意,time_zone的值必须进行URL编码。
您还可以在连接字符串中设置其他系统变量。
英文:
The correct way is to set a timezone in the connection string:
sql.Open("mysql", "root@tcp(127.0.0.1:3306)/dbname?charset=utf8&parseTime=true&time_zone=%2B00%3A00")
Note that time_zone value must be urlencoded.
Also you can set other system variables in conn string.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论