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