mysql.go 1.04 KB
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())
	}
}