mysql.go
1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package database
import (
"common"
"database/sql"
"fmt"
"log"
"time"
_ "github.com/go-sql-driver/mysql"
)
var SqlDB *sql.DB
func Init(dbmysql common.Mysql) {
var err error
// 正式环境
/* dbUser := "icesimba_root"
dbPasswd := "Icesimba858680668866sdk121"
dbAddr := "rm-2zenjpu465r1ee1rd.mysql.rds.aliyuncs.com"
dbPort := "3306"
dbName := "icesimbasdk_pro"
*/
//测试环境
dbUser := dbmysql.UserName
dbPasswd := dbmysql.Password
dbAddr := dbmysql.Address
dbPort := dbmysql.Port
dbName := dbmysql.DBName
//预上线环境
/*
dbUser := "trump"
dbPasswd := "Trump123"
dbAddr := "rm-2zeia588lj1117u37.mysql.rds.aliyuncs.com"
dbPort := "3306"
dbName := "icesimbasdk_verification"
*/
connStr := dbUser + ":" + dbPasswd + "@tcp(" + dbAddr + ":" + dbPort + ")/" + dbName + "?charset=utf8"
SqlDB, err = sql.Open("mysql", connStr)
if err != nil {
log.Fatal(err.Error())
} else {
fmt.Println("数据库打开成功!")
}
err = SqlDB.Ping()
if err != nil {
log.Fatal(err.Error())
} else {
fmt.Println("数据库连接成功!", time.Now().UnixNano())
}
}