Add support for reading ~/.my.cnf

Description

I don't want to have to specify username and passwords on the command line for security reasons. Most MySQL clients support reading from ~/.my.cnf and also --defaults-file.

When it is ~/.my.cnf that I want to use I do not want to have to specify it with --defaults-file.

It seems trivial to add support to read the username and password from ~/.my.cnf when they have not been received from the command options, e.g.

Very basic example

package main import ( "fmt" "github.com/go-ini/ini" "os" ) func parseMyCnf(cfg string) (string, string, error) { mycnf, err := ini.Load(cfg) if err != nil { return "", "", err } return mycnf.Section("client").Key("user").String(), mycnf.Section("client").Key("password").String(), nil } func main() { var myuser, mypasswd string // Normal parsing of options occurs if myuser != "" || mypasswd != "" { fmt.Println("Credentials already set") os.Exit(0) } if myuser, mypasswd, err := parseMyCnf(os.Getenv("HOME") + "/.my.cnf"); err == nil { fmt.Printf("%s = %s\n", myuser, mypasswd) } else if err != nil { fmt.Println(err.Error()) os.Exit(1) } }

N.B. the parsing of the INI shown here may require additional options for a my.cnf, but this example is fine for a minimal one.

How to test

None

How to document

None

Smart Checklist

Activity

Roma Novikov April 28, 2020 at 2:38 PM

Looks like  https://perconadev.atlassian.net/browse/PMM-4879#icft=PMM-4879 should cover this one. So will close it.

 

and  the "bonus" part is covered in https://perconadev.atlassian.net/browse/PMM-612#icft=PMM-612, imho . 

But this is big change in architecture  so  need to keep it on hold for now  

C W November 19, 2019 at 10:54 AM

that is correct, so long as removing and adding the service back does not affect the mapping of the data.
However, bonus points for always reading the file when starting the service and not storing the credentials anywhere else slightly smiling face

Roma Novikov November 19, 2019 at 10:29 AM

to clarify: you expecting username and password from config file will be used when you adding Service to PMM.
NO magic updates in PMM side when you changes/ updates MySQL config file with new credentials?

Duplicate

Details

Assignee

Reporter

Priority

Components

Affects versions

Smart Checklist

Created November 18, 2019 at 7:35 PM
Updated March 6, 2024 at 5:12 AM
Resolved April 28, 2020 at 2:39 PM

Flag notifications