Skip to content

Commit fcabbae

Browse files
authored
Set utf8mb4 as the default charset on MySQL if CHARSET is unset (#12563)
MySQL in its infinite wisdom determines that UTF8 does not mean UTF8. Our install scripts know about this and will set CHARSET to utf8mb4 if we users choose this but... users who do not explicitly set this variable will default to utf8mb3 without knowing it. This PR changes the unset CHARSET value to utf8mb4 if users choose to use mysql. Signed-off-by: Andrew Thornton <[email protected]>
1 parent b78448e commit fcabbae

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

modules/setting/database.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,13 @@ func GetDBTypeByName(name string) string {
6060
func InitDBConfig() {
6161
sec := Cfg.Section("database")
6262
Database.Type = sec.Key("DB_TYPE").String()
63+
defaultCharset := "utf8"
6364
switch Database.Type {
6465
case "sqlite3":
6566
Database.UseSQLite3 = true
6667
case "mysql":
6768
Database.UseMySQL = true
69+
defaultCharset = "utf8mb4"
6870
case "postgres":
6971
Database.UsePostgreSQL = true
7072
case "mssql":
@@ -78,7 +80,7 @@ func InitDBConfig() {
7880
}
7981
Database.Schema = sec.Key("SCHEMA").String()
8082
Database.SSLMode = sec.Key("SSL_MODE").MustString("disable")
81-
Database.Charset = sec.Key("CHARSET").In("utf8", []string{"utf8", "utf8mb4"})
83+
Database.Charset = sec.Key("CHARSET").In(defaultCharset, []string{"utf8", "utf8mb4"})
8284
Database.Path = sec.Key("PATH").MustString(filepath.Join(AppDataPath, "gitea.db"))
8385
Database.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500)
8486
Database.MaxIdleConns = sec.Key("MAX_IDLE_CONNS").MustInt(2)

0 commit comments

Comments
 (0)