File tree 1 file changed +7
-6
lines changed
1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change 6
6
"flag"
7
7
"fmt"
8
8
"log"
9
+ "net/url"
9
10
"os"
10
11
"time"
11
12
)
@@ -71,6 +72,12 @@ func main() {
71
72
72
73
connstr := dbInfo .User + ":" + dbInfo .Password + "@tcp(" + dbInfo .HostPort +
73
74
")/" + dbInfo .Database + "?strict=true&charset=utf8&parseTime=True&loc=UTC"
75
+ if dbInfo .Timezone != "" {
76
+ // Quoting with %27 is needed
77
+ // https://github.com/go-sql-driver/mysql/issues/405
78
+ connstr = connstr + "&time_zone=%27" + url .QueryEscape (dbInfo .Timezone ) + "%27"
79
+ }
80
+ log .Println (connstr )
74
81
75
82
db , err := sql .Open ("mysql" , connstr )
76
83
if err != nil {
@@ -79,12 +86,6 @@ func main() {
79
86
}
80
87
defer db .Close ()
81
88
82
- if dbInfo .Timezone != "" {
83
- if _ , err := db .Exec ("SET @time_zone = ?" , dbInfo .Timezone ); err != nil {
84
- log .Fatal (err )
85
- }
86
- }
87
-
88
89
if err = run (db ); err != nil {
89
90
log .Println (err )
90
91
// As os.Exit shortcircuits defers, we have to close explicitely
You can’t perform that action at this time.
0 commit comments