mysql.go
1.04 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
55
package database
import (
"database/sql"
"fmt"
"time"
_ "github.com/go-sql-driver/mysql"
)
var SqlDB *sql.DB
func init() {
var err error //rm-2zeia588lj1117u37o.mysql.rds.aliyuncs.com:3306
//正式服务器
/*
var (
sqlUser = "icesimba_root"
sqlPas = "Icesimba858680668866sdk121"
sqlPro = "tcp"
sqlUrl = "rm-2zenjpu465r1ee1rd.mysql.rds.aliyuncs.com"
sqlPort = "3306"
sqlDb = "icesimbasdk_pro"
sqlEnco = "utf8"
)
*/
var (
sqlUser = "trump"
sqlPas = "Trump123"
sqlPro = "tcp"
sqlUrl = "rm-2zeia588lj1117u37o.mysql.rds.aliyuncs.com"
sqlPort = "3306"
sqlDb = "icesimbasdk_test"
sqlEnco = "utf8"
)
sqlConn := sqlUser + ":" + sqlPas +
"@" + sqlPro +
"(" + sqlUrl + ":" + sqlPort + ")/" +
sqlDb +
"?charset=" + sqlEnco
SqlDB, err = sql.Open("mysql", sqlConn)
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println("数据库打开成功!")
}
err = SqlDB.Ping()
if err != nil {
fmt.Println(err.Error())
} else {
fmt.Println("数据库连接成功!", time.Now().UnixNano())
}
}