首页 > 数据库 >golang各类数据库连接方式

golang各类数据库连接方式

时间:2022-10-08 10:34:41浏览次数:56  
标签:github err url 数据库 db golang sql com 连接

常用数据库驱动列表

    //odbc
    _ "github.com/alexbrainman/odbc"
    //mssql
    _ "github.com/denisenkom/go-mssqldb"
    //mysql
    _ "github.com/go-sql-driver/mysql"
    //oracle
    _ "github.com/godror/godror"

    // _ "github.com/ibmdb/go_ibm_db"
    //pgsql
    _ "github.com/jackc/pgx/v4/stdlib"

常用数据库驱动连接例子列表

switch conf.DbType {
    case Mysql:
         url:="userName:password@tcp(127.0.0.1:3306)/test?charset=utf8"
         db, err = sql.Open("mysql", url)
    case Oracle:
        url := `user="a" password="b" connectString="127.0.0.1:1521/test"`
        db, err = sql.Open("godror", url)
    case Mssql:
        url := `sqlserver://name:[email protected]:1433?database=test`
        db, err = sql.Open("sqlserver", url)
    case Pgsql:
        url := `postgres://name:[email protected]:5432/test?sslmode=disable`
        db, err = sql.Open("pgx", url)
    case Db2:
        url := `DSN=133DB2;uid=userName;pwd=passwd`
        db, err = sql.Open("odbc", url)
    }

 

标签:github,err,url,数据库,db,golang,sql,com,连接
From: https://www.cnblogs.com/chb39335580/p/16768168.html

相关文章