dsn

package
v0.0.0-...-3eaa125 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 28, 2022 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ParseTimeParam    = "parseTime=true"
	TimezoneParam     = `time_zone='%2b00%3a00'`
	LocationParam     = "loc=UTC"
	OldPasswordsParam = "allowOldPasswords=true"
	HiddenPassword    = "***"
)

Variables

View Source
var (
	// ErrNoSocket is returned when GetSocketFromProcessLists can't locate socket.
	ErrNoSocket = errors.New("cannot auto-detect MySQL socket")
)

Functions

func GetSocket

func GetSocket(ctx context.Context, dsn string) (string, error)

GetSocket tries to detect and return path to the MySQL socket.

func GetSocketFromNetstat

func GetSocketFromNetstat(ctx context.Context) (string, error)

GetSocketFromNetstat will loop through list of open sockets and try to find one matching `mysql` word. Warning: this function returns the socket for the FIRST entry it founds. If there are more sockets containing `mysql` word, only the first one will be detected.

func GetSocketFromProcessList

func GetSocketFromProcessList(ctx context.Context) (string, error)

GetSocketFromProcessList will loop through the list of PIDs until it finds a process named 'mysqld' and the it will try to get the socket by querying the open network connections for that process. Warning: this function returns the socket for the FIRST mysqld process it founds. If there are more than one MySQL instance, only the first one will be detected.

func GetSocketFromTCPConnection

func GetSocketFromTCPConnection(ctx context.Context, dsn string) (socket string, err error)

GetSocketFromTCPConnection will try to get socket path by connecting to MySQL localhost TCP port. This is not reliable as TCP connections may be not allowed.

func GetSocketsFromPID

func GetSocketsFromPID(ctx context.Context, pid string) ([]string, error)

GetSocketsFromPID returns currently open UNIX domain socket files by process identifier (PID).

func HidePassword

func HidePassword(dsn string) string

Types

type DSN

type DSN struct {
	Username string
	Password string
	Hostname string
	Port     string
	Socket   string
	//
	DefaultsFile string
	Protocol     string
	//
	DefaultDb string
	Params    []string
}

func Defaults

func Defaults(defaultsFile string) (DSN, error)

func ParseMySQLDefaults

func ParseMySQLDefaults(output string) DSN

func (DSN) AutoDetect

func (dsn DSN) AutoDetect(ctx context.Context) (DSN, error)

func (DSN) String

func (dsn DSN) String() string

func (DSN) Verify

func (dsn DSN) Verify() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL