dongyan4157 2013-05-26 18:17
浏览 99

转到-连接到外部mysql数据库

I'm rather new to use go and am having issues connecting to an external mysql database. I'm using the go-sql-driver which seams rather nice. Suggestions to other drivers are welcomed!

this is the whole program:

import (
  "database/sql"
   _ "github.com/go-sql-driver/mysql"
  "fmt"
)

const (
  DB_HOST = "tcp(http://thedburl.com)"
  DB_NAME = "nameofdatabase"
  DB_USER = "username"
  DB_PW = "password"
)

func main() {
  dsn := DB_USER + ":" + DB_PW + "@" + DB_HOST + "/" + DB_NAME + "?charset=uf8"
  db, err := sql.Open("mysql", dsn)

  if err != nil {
       fmt.Println("shiiet didn't work yo! Initialization failed")
  }

  defer db.Close() // go's purty cool

  var str string
  q := "SELECT * FROM forums"
  err = db.QueryRow(q).Scan(&str)

  if err != nil {
      fmt.Println(err)
  }

  fmt.Println(str)
}

On the request I'm recieving the following error

 "GetAddrInfoW: The specified class was not found."

Any ideas? I've siting for hours on the webs, and can't seem to solve the problem. It might be worth noting that I have used the same database service many times in java.

  • 写回答

1条回答 默认 最新

  • doufubu2518 2013-05-27 11:09
    关注

    Thanks for everyones answers.

    The mysql drivers for Go are at the current time having a hard time dealing with older mysql versions. Specifically this issue happened due to the incompatibility of mysql's old_password from 2006. Therefore working with older databases is a pain. (source: https://github.com/go-sql-driver/mysql/wiki/old_passwords) - My educated guess also applies to the mymysql driver whom throws the "bad connection" error. Which basicly times out after repetitive attempts of connection.

    Special thanks to @Lepidosteus who's answer made me discover the real problem.

    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘