mysql: fix encoding in connection string (#20192)
This commit is contained in:
+10
-5
@@ -4,12 +4,12 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
"reflect"
|
"reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/VividCortex/mysqlerr"
|
"github.com/VividCortex/mysqlerr"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/setting"
|
"github.com/grafana/grafana/pkg/setting"
|
||||||
|
|
||||||
"github.com/go-sql-driver/mysql"
|
"github.com/go-sql-driver/mysql"
|
||||||
@@ -24,6 +24,10 @@ func init() {
|
|||||||
tsdb.RegisterTsdbQueryEndpoint("mysql", newMysqlQueryEndpoint)
|
tsdb.RegisterTsdbQueryEndpoint("mysql", newMysqlQueryEndpoint)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func characterEscape(s string, escapeChar string) string {
|
||||||
|
return strings.Replace(s, escapeChar, url.QueryEscape(escapeChar), -1)
|
||||||
|
}
|
||||||
|
|
||||||
func newMysqlQueryEndpoint(datasource *models.DataSource) (tsdb.TsdbQueryEndpoint, error) {
|
func newMysqlQueryEndpoint(datasource *models.DataSource) (tsdb.TsdbQueryEndpoint, error) {
|
||||||
logger := log.New("tsdb.mysql")
|
logger := log.New("tsdb.mysql")
|
||||||
|
|
||||||
@@ -31,12 +35,13 @@ func newMysqlQueryEndpoint(datasource *models.DataSource) (tsdb.TsdbQueryEndpoin
|
|||||||
if strings.HasPrefix(datasource.Url, "/") {
|
if strings.HasPrefix(datasource.Url, "/") {
|
||||||
protocol = "unix"
|
protocol = "unix"
|
||||||
}
|
}
|
||||||
|
|
||||||
cnnstr := fmt.Sprintf("%s:%s@%s(%s)/%s?collation=utf8mb4_unicode_ci&parseTime=true&loc=UTC&allowNativePasswords=true",
|
cnnstr := fmt.Sprintf("%s:%s@%s(%s)/%s?collation=utf8mb4_unicode_ci&parseTime=true&loc=UTC&allowNativePasswords=true",
|
||||||
datasource.User,
|
characterEscape(datasource.User, ":"),
|
||||||
datasource.DecryptedPassword(),
|
characterEscape(datasource.DecryptedPassword(), "@"),
|
||||||
protocol,
|
protocol,
|
||||||
datasource.Url,
|
characterEscape(datasource.Url, ")"),
|
||||||
datasource.Database,
|
characterEscape(datasource.Database, "?"),
|
||||||
)
|
)
|
||||||
|
|
||||||
tlsConfig, err := datasource.GetTLSConfig()
|
tlsConfig, err := datasource.GetTLSConfig()
|
||||||
|
|||||||
Reference in New Issue
Block a user