英文:
golang editing previously set flag. MySQL error 1045
问题
我在用户输入后设置一个标志来作为连接参数用于MySQL数据库,但是遇到了问题。以下是我的代码片段:
func init() {
flag.StringVar(&flagUser, "user", "root", "User")
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter username: ")
inputUser, _ := reader.ReadString('\n')
f := flag.Lookup("user")
if inputUser != f.Value.String() {
flag.StringVar(&flagUser, "user", inputUser, "User")
}
flag.Parse()
}
即使我只调用一次flag.Parse,并且用户输入也是"root",我仍然得到一个1045错误("mysql access denied for user root@localhost"),如果我不编辑标志就不会出现这个错误。我非常感谢对这个问题的任何建议。
再次感谢你的帮助!
英文:
I'm having trouble setting a flag after user input to use as a connection parameter to a MySQL Database. Below is a snippet of my code:
func init() {
flag.StringVar(&flagUser, "user", "root", "User")
reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter username: ")
inputUser, _ := reader.ReadString('\n')
f := flag.Lookup("user")
if inputUser != f.Value.String() {
flag.StringVar(&flagUser, "user", inputUser, "User")
}
flag.Parse()
}
Even if I call flag.Parse only once and the user input is also "root", i get a 1045 ("mysql access denied for user root@localhost"), which doesn't occur if i don't edit the flag. I would really appreciate any suggestions on this issue.
Once again, thanks for the help!
答案1
得分: 0
在进行了更多的研究后,我发现没有必要通过用户输入来编辑指定连接参数的标志,因为在运行Go应用程序时可以传递这些MySQL参数(例如:-user,-p等)。
英文:
After doing some more research I've found that there's no need to edit a flag specifying a connection parameter through user input, since it is possible to pass such mysql parameters when running a go application (i.e. : -user, -p, etc).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论