Duplicate
Details
Assignee
UnassignedUnassignedReporter
C WC WPriority
MediumComponents
Labels
Affects versions
Details
Details
Assignee
Unassigned
UnassignedReporter
C W
C WPriority
Components
Labels
Affects versions
Smart Checklist
Smart Checklist
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
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.