优化连接方式

优化连接方式
master
wangsiyuan 2023-06-05 17:20:02 +08:00
parent bb36010ca0
commit ee30606ddd
1 changed files with 8 additions and 8 deletions

View File

@ -6,9 +6,9 @@ import (
"github.com/go-sql-driver/mysql"
)
func ImportDatabaseToString() {
func ImportDatabaseToString(dsn string) {
mysql.RegisterLocalFile("C:/Users/wangh/Desktop/code/checkIP/db/GeoLite2-City-Blocks-IPv4-string.csv")
db, err := sql.Open("mysql", "root:990821@tcp(192.168.2.20:3306)/checkip")
db, err := sql.Open("mysql", dsn)
if err != nil {
fmt.Println("数据库连接错误:", err)
return
@ -66,9 +66,9 @@ CREATE TABLE geolite2_city_ipv4_string (
fmt.Println("表geolite2_city_ipv4_string数据加载完成")
}
func ImportDatabaseToHex() {
func ImportDatabaseToHex(dsn string) {
mysql.RegisterLocalFile("C:/Users/wangh/Desktop/code/checkIP/db/GeoLite2-City-Blocks-IPv4-hex.csv")
db, err := sql.Open("mysql", "root:990821@tcp(192.168.2.20:3306)/checkip")
db, err := sql.Open("mysql", dsn)
if err != nil {
fmt.Println("数据库连接错误:", err)
return
@ -126,9 +126,9 @@ CREATE TABLE geolite2_city_ipv4_hex (
fmt.Println("表geolite2_city_ipv4_hex数据加载完成")
}
func ImportLocation_zhCN() {
func ImportLocation_zhCN(dsn string) {
mysql.RegisterLocalFile("C:/Users/wangh/Desktop/code/checkIP/db/GeoLite2-City-Locations-zh-CN.csv")
db, err := sql.Open("mysql", "root:990821@tcp(192.168.2.20:3306)/checkip")
db, err := sql.Open("mysql", dsn)
if err != nil {
fmt.Println("数据库连接错误:", err)
return
@ -188,9 +188,9 @@ set country_iso_code = nullif(@country_iso_code, ''),
fmt.Println("表geolite2_city_locations_zh_cn数据加载完成")
}
func ImportLocation_en() {
func ImportLocation_en(dsn string) {
mysql.RegisterLocalFile("C:/Users/wangh/Desktop/code/checkIP/db/GeoLite2-City-Locations-en.csv")
db, err := sql.Open("mysql", "root:990821@tcp(192.168.2.20:3306)/checkip")
db, err := sql.Open("mysql", dsn)
if err != nil {
fmt.Println("数据库连接错误:", err)
return