如果我使用golang的sql连接MySQL时,我的用户名包含@符号会怎么样?

huangapple go评论76阅读模式
英文:

What if my user name contains at sign '@' when use golang sql to connect mysql?

问题

应用程序需要一个用户名包含@字符的用户,我发现当用户名包含@且密码为空时,golang-sql会崩溃,就像下面这样:

sql.Open("mysql", "root@proxy@tcp(172.21.30.22:3306)..")
英文:

Application needs a user whose name contains @ character, I found it seems that golang-sql will crash while name contains @ and password is empty, just like

sql.Open("mysql", "root@proxy@tcp(172.21.30.22:3306)..")

答案1

得分: 1

当您在用户名中使用特殊字符时,应使用引号将用户名与域名分隔开。

例如:

sql.Open("mysql", "'root@proxy'@'tcp(172.21.30.22:3306)'")
英文:

When you use special characters in your usernames you should use quotes to separate the username from the domain name

For example

sql.Open("mysql", "'root@proxy'@'tcp(172.21.30.22:3306)'")

huangapple
  • 本文由 发表于 2021年12月6日 21:37:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/70246386.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定