在编译系统上,下面的 Golang 代码运行良好,但是当…

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

the below golang code works fine on the system conpiled, however when

问题

以下是翻译好的代码:

package main

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

func main() {

	// 打开数据库连接
	db, err := sql.Open("mysql", "root:passwd@/mysql")
	if err != nil {
		fmt.Printf("无法打开数据库连接!\n")
		return
	}
	defer db.Close()

	// 执行查询
	rows, err := db.Exec("update user set password=PASSWORD('NEWPASSWORD') where User='root'")
	_ = rows
	if err != nil {
		fmt.Printf("无法执行更新查询!\n")
		return
	}
}

请注意,这只是代码的翻译部分,不包括任何其他内容。

英文:

The below golang code works fine on the system compiled, however when the compiled binary is moved to another system it fails to connect database. What thing I am doing wrong here in terms of packaging.

package main

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

func main() {

        // Open database connection
    db, err := sql.Open("mysql", "root:passwd@/mysql")
    if err != nil {
        fmt.Printf("Cannot open connection to schema !!!. \n")
        return
    }
    defer db.Close()

    // Execute the query
    rows, err := db.Exec("update user set password=PASSWORD("NEWPASSWORD") where User='root'")
    _ = rows
    if err != nil {
        fmt.Printf("Cannot execute query update !!! \n")
        return
    }
}

答案1

得分: 1

问题已解决。问题出在对旧密码验证的支持上。必须添加以下内容:

> db, err := sql.Open("mysql", "root:passwd@/mysql?allowOldPasswords=1")

详细信息请参考:https://github.com/go-sql-driver/mysql/wiki/old_passwords

英文:

The issue got resolved. The problem was with support for legacy old password authentication. Had to add append

> db, err := sql.Open("mysql", "root:passwd@/mysql?allowOldPasswords=1")

https://github.com/go-sql-driver/mysql/wiki/old_passwords

huangapple
  • 本文由 发表于 2017年5月25日 20:43:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/44180926.html
匿名

发表评论

匿名网友

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

确定