diff --git a/commands/migrate.go b/commands/migrate.go index 4c040e0..8a5b22d 100644 --- a/commands/migrate.go +++ b/commands/migrate.go @@ -17,6 +17,8 @@ func (c *MigrateCommand) Execute([]string) error { PG2MySQL.Config.MySQL.Password, PG2MySQL.Config.MySQL.Host, PG2MySQL.Config.MySQL.Port, + PG2MySQL.Config.MySQL.Charset, + PG2MySQL.Config.MySQL.Collation, ) err := mysql.Open() diff --git a/commands/validate.go b/commands/validate.go index e201608..70263b8 100644 --- a/commands/validate.go +++ b/commands/validate.go @@ -15,6 +15,8 @@ func (c *ValidateCommand) Execute([]string) error { PG2MySQL.Config.MySQL.Password, PG2MySQL.Config.MySQL.Host, PG2MySQL.Config.MySQL.Port, + PG2MySQL.Config.MySQL.Charset, + PG2MySQL.Config.MySQL.Collation, ) err := mysql.Open() diff --git a/commands/verify.go b/commands/verify.go index d68b3da..5c122e7 100644 --- a/commands/verify.go +++ b/commands/verify.go @@ -15,6 +15,8 @@ func (c *VerifyCommand) Execute([]string) error { PG2MySQL.Config.MySQL.Password, PG2MySQL.Config.MySQL.Host, PG2MySQL.Config.MySQL.Port, + PG2MySQL.Config.MySQL.Charset, + PG2MySQL.Config.MySQL.Collation, ) err := mysql.Open() diff --git a/config.go b/config.go index e408ddf..a900f2b 100644 --- a/config.go +++ b/config.go @@ -2,11 +2,13 @@ package pg2mysql type Config struct { MySQL struct { - Database string `yaml:"database"` - Username string `yaml:"username"` - Password string `yaml:"password"` - Host string `yaml:"host"` - Port int `yaml:"port"` + Database string `yaml:"database"` + Username string `yaml:"username"` + Password string `yaml:"password"` + Host string `yaml:"host"` + Port int `yaml:"port"` + Charset string `yaml:"charset"` + Collation string `yaml:"collation"` } `yaml:"mysql"` PostgreSQL struct { diff --git a/mysql.go b/mysql.go index 02c11f0..8c70b86 100644 --- a/mysql.go +++ b/mysql.go @@ -13,7 +13,17 @@ func NewMySQLDB( password string, host string, port int, + charset string, + collation string, ) DB { + if (charset == "") { + charset = "utf8" + } + + if (collation == "") { + collation = "utf8_general_ci" + } + config := mysql.Config{ User: username, Passwd: password, @@ -22,7 +32,8 @@ func NewMySQLDB( Addr: fmt.Sprintf("%s:%d", host, port), MultiStatements: true, Params: map[string]string{ - "charset": "utf8", + "charset": charset, + "collation": collation, "parseTime": "True", }, }