英文:
Unknown authentication response: 10 Postresql golang
问题
我在使用golang连接到PostgreSQL时遇到了错误。
错误信息:pq: unknown authentication response: 10
代码:
cfg := config{
Host: "localhost",
Port: 5432,
Username: "postgres",
Password: "ellez2004",
DBname: "app",
}
pconfig := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",cfg.Host,cfg.Port,cfg.Password,cfg.Password,cfg.DBname)
db,err := sql.Open("postgres",pconfig)
if err != nil {
log.Fatal(err.Error())
}
defer db.Close();
insert := insert into "User" ("firstname","lastname") values('Allaz','Bairamov')
_ ,err = db.Exec(insert);
if err != nil {
fmt.Println("error ---", err.Error());
}
fmt.Println("success");
http.ListenAndServe(":8000", nil)
请帮忙解决:)
英文:
I get an error while connect to postresql with golang
ERROR ----------- pq: unknown authentication response: 10
CODE:
cfg := config{
Host: "localhost",
Port: 5432,
Username: "postgres",
Password: "ellez2004",
DBname: "app",
}
pconfig := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",cfg.Host,cfg.Port,cfg.Password,cfg.Password,cfg.DBname)
db,err := sql.Open("postgres",pconfig)
if err != nil {
log.Fatal(err.Error())
}
defer db.Close();
insert := `insert into "User" ("firstname","lastname") values('Allaz','Bairamov')`
_ ,err = db.Exec(insert);
if err != nil {
fmt.Println("error ---", err.Error());
}
fmt.Println("success");
http.ListenAndServe(":8000", nil)
Please help:)
答案1
得分: 1
似乎有一个拼写错误。应该是.Username而不是.Password
pconfig := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",cfg.Host,cfg.Port,cfg.Username,cfg.Password,cfg.DBname)
另外,请确保所有参数与Postgres连接匹配
Host: "localhost", // 您托管Postgres服务器的位置
Port: 5432, // Postgres的默认端口
Username: "postgres", // 这是访问数据库的用户凭据
Password: "ellez2004", // 对应的密码
DBname: "app", // 数据库模式名称
英文:
Seems like there is typo. Should be .Username not .Password
pconfig := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable",cfg.Host,cfg.Port,cfg.Password,cfg.Password,cfg.DBname)
Else, try make sure all the parameters tally with Postgres Connection
Host: "localhost", // where you host your Postgres server
Port: 5432, // default port for Postgres
Username: "postgres", // this is user credential to access of the database
Password: "ellez2004", // corresponding password
DBname: "app", // the database schema name
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论