英文:
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")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论