Documentation ¶
Overview ¶
Package mylogin reads and writes ~/.mylogin.cnf created by mysql_config_editor.
Reference documentation:
- https://dev.mysql.com/doc/refman/8.0/en/mysql-config-editor.html
- https://dev.mysql.com/doc/refman/8.0/en/option-file-options.html#option_general_login-path
Example:
mysql_config_editor set --login-path=foo --user=bar -p
For usage examples, see the utilies in the same repo.
Index ¶
Constants ¶
const DefaultSection = "client"
DefaultSection is the name of the base section used by all MySQL client tools.
Variables ¶
This section is empty.
Functions ¶
func DefaultFile ¶
func DefaultFile() string
DefaultFile returns the path to the default mylogin.cnf file:
Windows: %APPDATA%/MySQL/.mylogin.cnf others: ~/.mylogin.cnf
If the environment variable MYSQL_TEST_LOGIN_FILE is set that path is returned instead.
Types ¶
type File ¶
type File interface { // The key used for encrypting the file Key() Key // Byte ordering for saving int32 chunk sizes ByteOrder() binary.ByteOrder // The plaintext content of the file PlainText() io.Reader }
File is the full structure of a mylogin.cnf file.
type Key ¶
type Key [20]byte
Key is a key used for encryption of mylogin.cnf files.
func NewKey ¶
NewKey creates a new key from a source of random bytes. See math/rand.Read and crypto/rand.Read as possible sources.
The generated key has the 3 high bits cleared so each byte is non-printable.
type Login ¶
type Login struct { User *string `json:"user,omitempty"` Password *string `json:"password,omitempty"` Host *string `json:"host,omitempty"` // TCP hostname Port *string `json:"port,omitempty"` // TCP port Socket *string `json:"socket,omitempty"` // Unix socket path }
Login is the content of a section of mylogin.cnf.
func ReadLogin ¶
ReadLogin reads a mylogin.cnf file, extracts the requested sections and merges them to obtain a single Login (that may be empty).
func (*Login) DSN ¶
DSN builds a DSN for github.com/go-sql-driver/mysql
The DSN returned always has a '/' at the end. The DSN for an empty Login is just "/".
type Sections ¶
type Sections []Section
Sections represents the structured content on the plaintext of mylogin.cnf.
func Parse ¶
Parse parses the plaintext content of a mylogin.cnf file and returns the structured content.
func ReadSections ¶
ReadSections reads all Sections of a mylogin.cnf file.