Documentation
¶
Overview ¶
Package mysql is the plugin for MySQL driver.
Index ¶
- func BuildDSN(username, password, protocol, host, port, databaseName string, params []string) string
- func GetColumnTypeCanonicalSynonym(columnType string) string
- func IsCurrentTimestampLike(s string) bool
- func QuoteIdentifier(name string) string
- func UnescapeExpressionDefault(s string) string
- func UnquoteMySQLString(s string) string
- func ValidateExtraConnectionParameters(params map[string]string) error
- type Driver
- func (d *Driver) Close(context.Context) error
- func (d *Driver) GetDB() *sql.DB
- func (d *Driver) Open(ctx context.Context, dbType storepb.Engine, connCfg db.ConnectionConfig) (db.Driver, error)
- func (d *Driver) Ping(ctx context.Context) error
- func (d *Driver) StopConnectionByID(id string) error
- func (d *Driver) SyncDBSchema(ctx context.Context) (metadata *storepb.DatabaseSchemaMetadata, err error)
- func (d *Driver) SyncInstance(ctx context.Context) (*db.InstanceMetadata, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildDSN ¶
func BuildDSN(username, password, protocol, host, port, databaseName string, params []string) string
BuildDSN renders the connection string for a MySQL-wire data source.
databaseName is not a constant chosen at registration time: a schema sync reads it out of the target instance's own catalog. Interpolated as-is, a database named `app?tls=false&` would end the DSN's path segment and turn the rest into driver parameters — the connection would drop TLS, point at the database `app` and let whoever can create a database on the target rewrite the connection the platform opens with its privileged sync account. The name is therefore escaped with url.PathEscape, which is what the driver's own Config.FormatDSN applies to DBName, so an escaped name round-trips through ParseDSN unchanged.
It is exported so StarRocks and Doris build their DSN the same way instead of re-deriving the template.
func GetColumnTypeCanonicalSynonym ¶
GetColumnTypeCanonicalSynonym returns the canonical synonyms of the given column types, returns the original one if no synonym was found.
func IsCurrentTimestampLike ¶
func QuoteIdentifier ¶
QuoteIdentifier backtick-quotes a MySQL-wire identifier. Identifiers cannot be bound as statement parameters, so an embedded backtick is escaped by doubling. It is exported so the other MySQL-wire drivers (StarRocks, Doris) quote identifiers the same way instead of letting the escaping drift.
func UnescapeExpressionDefault ¶
UnescapeExpressionDefault unescapes the default expression for MySQL. This handles the second layer of escaping that MySQL applies when storing expression defaults (like DEFAULT (UUID())) in system catalogs. MySQL stores expressions as escaped strings internally, separate from QUOTE() escaping.
func UnquoteMySQLString ¶
UnquoteMySQLString unescapes a string that was escaped by MySQL's QUOTE() function. MySQL's QUOTE() function escapes: - \ → \\ - ' → \' - ASCII NUL (0x00) → \0 - Control-Z (0x1A) → \Z
func ValidateExtraConnectionParameters ¶
ValidateExtraConnectionParameters validates that no dangerous parameters are present. It is exported so the other MySQL-wire drivers (StarRocks, Doris) enforce the same allowlist instead of letting the check drift.
Types ¶
type Driver ¶
type Driver struct {
// contains filtered or unexported fields
}
Driver is the MySQL driver.
func (*Driver) Open ¶
func (d *Driver) Open(ctx context.Context, dbType storepb.Engine, connCfg db.ConnectionConfig) (db.Driver, error)
Open opens a MySQL driver.
func (*Driver) StopConnectionByID ¶
func (*Driver) SyncDBSchema ¶
func (d *Driver) SyncDBSchema(ctx context.Context) (metadata *storepb.DatabaseSchemaMetadata, err error)
SyncDBSchema syncs a single database schema. A database the target no longer has is reported as common.NotFound, which is what tells a caller mirroring the target's inventory apart from a permission or connectivity failure.
func (*Driver) SyncInstance ¶
SyncInstance syncs the instance.