Last active
April 9, 2020 13:19
-
-
Save hitzhangjie/1bf111e03f9359081d5c52ec3ae490ef to your computer and use it in GitHub Desktop.
database connect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//连接数据库示例(通过*sql.DB执行数据库操作,其内部维护了数据库连接池) | |
func OpenDatabase(ipport, database, user, pwd string) (*sql.DB, error) { | |
connStr := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4", user, pwd, ipport, database) | |
return sql.Open("mysql", connStr) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment