Skip to content

Commit ce46834

Browse files
authored
Remove "CHARSET" config option for MySQL, always use "utf8mb4" (#25413)
In modern days, there is no reason to make users set "charset" anymore. Close #25378 ## ⚠️ BREAKING The key `[database].CHARSET` was removed completely as every newer (>10years) MySQL database supports `utf8mb4` already. There is a (deliberately) undocumented new fallback option if anyone still needs to use it, but we don't recommend using it as it simply causes problems.
1 parent dfd19fa commit ce46834

File tree

8 files changed

+9
-46
lines changed

8 files changed

+9
-46
lines changed

custom/conf/app.example.ini

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -344,9 +344,6 @@ NAME = gitea
344344
USER = root
345345
;PASSWD = ;Use PASSWD = `your password` for quoting if you use special characters in the password.
346346
;SSL_MODE = false ; either "false" (default), "true", or "skip-verify"
347-
;CHARSET = utf8mb4 ;either "utf8" or "utf8mb4", default is "utf8mb4".
348-
;;
349-
;; NOTICE: for "utf8mb4" you must use MySQL InnoDB > 5.6. Gitea is unable to check this.
350347
;;
351348
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
352349
;;

docs/content/doc/administration/config-cheat-sheet.en-us.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ The following configuration set `Content-Type: application/vnd.android.package-a
443443
- `SQLITE_TIMEOUT`: **500**: Query timeout for SQLite3 only.
444444
- `SQLITE_JOURNAL_MODE`: **""**: Change journal mode for SQlite3. Can be used to enable [WAL mode](https://www.sqlite.org/wal.html) when high load causes write congestion. See [SQlite3 docs](https://www.sqlite.org/pragma.html#pragma_journal_mode) for possible values. Defaults to the default for the database file, often DELETE.
445445
- `ITERATE_BUFFER_SIZE`: **50**: Internal buffer size for iterating.
446-
- `CHARSET`: **utf8mb4**: For MySQL only, either "utf8" or "utf8mb4". NOTICE: for "utf8mb4" you must use MySQL InnoDB > 5.6. Gitea is unable to check this.
447446
- `PATH`: **data/gitea.db**: For SQLite3 only, the database file path.
448447
- `LOG_SQL`: **true**: Log the executed SQL.
449448
- `DB_RETRIES`: **10**: How many ORM init / DB connect attempts allowed.

docs/content/doc/help/faq.en-us.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,6 @@ Please run `gitea convert`, or run `ALTER DATABASE database_name CHARACTER SET u
396396
for the database_name and run `ALTER TABLE table_name CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;`
397397
for each table in the database.
398398

399-
You will also need to change the app.ini database charset to `CHARSET=utf8mb4`.
400-
401399
## Why are Emoji displaying only as placeholders or in monochrome
402400

403401
Gitea requires the system or browser to have one of the supported Emoji fonts installed, which are Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol, Noto Color Emoji and Twemoji Mozilla. Generally, the operating system should already provide one of these fonts, but especially on Linux, it may be necessary to install them manually.

modules/setting/database.go

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ import (
1212
"path/filepath"
1313
"strings"
1414
"time"
15-
16-
"code.gitea.io/gitea/modules/log"
1715
)
1816

1917
var (
@@ -36,7 +34,7 @@ var (
3634
SSLMode string
3735
Path string
3836
LogSQL bool
39-
Charset string
37+
MysqlCharset string
4038
Timeout int // seconds
4139
SQLiteJournalMode string
4240
DBConnectRetries int
@@ -60,11 +58,6 @@ func LoadDBSetting() {
6058
func loadDBSetting(rootCfg ConfigProvider) {
6159
sec := rootCfg.Section("database")
6260
Database.Type = DatabaseType(sec.Key("DB_TYPE").String())
63-
defaultCharset := "utf8"
64-
65-
if Database.Type.IsMySQL() {
66-
defaultCharset = "utf8mb4"
67-
}
6861

6962
Database.Host = sec.Key("HOST").String()
7063
Database.Name = sec.Key("NAME").String()
@@ -74,10 +67,7 @@ func loadDBSetting(rootCfg ConfigProvider) {
7467
}
7568
Database.Schema = sec.Key("SCHEMA").String()
7669
Database.SSLMode = sec.Key("SSL_MODE").MustString("disable")
77-
Database.Charset = sec.Key("CHARSET").In(defaultCharset, []string{"utf8", "utf8mb4"})
78-
if Database.Type.IsMySQL() && defaultCharset != "utf8mb4" {
79-
log.Error("Deprecated database mysql charset utf8 support, please use utf8mb4 or convert utf8 to utf8mb4.")
80-
}
70+
Database.MysqlCharset = sec.Key("MYSQL_CHARSET").MustString("utf8mb4") // do not document it, end users won't need it.
8171

8272
Database.Path = sec.Key("PATH").MustString(filepath.Join(AppDataPath, "gitea.db"))
8373
Database.Timeout = sec.Key("SQLITE_TIMEOUT").MustInt(500)
@@ -101,9 +91,9 @@ func loadDBSetting(rootCfg ConfigProvider) {
10191
// DBConnStr returns database connection string
10292
func DBConnStr() (string, error) {
10393
var connStr string
104-
Param := "?"
105-
if strings.Contains(Database.Name, Param) {
106-
Param = "&"
94+
paramSep := "?"
95+
if strings.Contains(Database.Name, paramSep) {
96+
paramSep = "&"
10797
}
10898
switch Database.Type {
10999
case "mysql":
@@ -116,15 +106,15 @@ func DBConnStr() (string, error) {
116106
tls = "false"
117107
}
118108
connStr = fmt.Sprintf("%s:%s@%s(%s)/%s%scharset=%s&parseTime=true&tls=%s",
119-
Database.User, Database.Passwd, connType, Database.Host, Database.Name, Param, Database.Charset, tls)
109+
Database.User, Database.Passwd, connType, Database.Host, Database.Name, paramSep, Database.MysqlCharset, tls)
120110
case "postgres":
121-
connStr = getPostgreSQLConnectionString(Database.Host, Database.User, Database.Passwd, Database.Name, Param, Database.SSLMode)
111+
connStr = getPostgreSQLConnectionString(Database.Host, Database.User, Database.Passwd, Database.Name, paramSep, Database.SSLMode)
122112
case "mssql":
123113
host, port := ParseMSSQLHostPort(Database.Host)
124114
connStr = fmt.Sprintf("server=%s; port=%s; database=%s; user id=%s; password=%s;", host, port, Database.Name, Database.User, Database.Passwd)
125115
case "sqlite3":
126116
if !EnableSQLite3 {
127-
return "", errors.New("this binary version does not build support for SQLite3")
117+
return "", errors.New("this Gitea binary was not built with SQLite3 support")
128118
}
129119
if err := os.MkdirAll(path.Dir(Database.Path), os.ModePerm); err != nil {
130120
return "", fmt.Errorf("Failed to create directories: %w", err)
@@ -136,7 +126,7 @@ func DBConnStr() (string, error) {
136126
connStr = fmt.Sprintf("file:%s?cache=shared&mode=rwc&_busy_timeout=%d&_txlock=immediate%s",
137127
Database.Path, Database.Timeout, journalMode)
138128
default:
139-
return "", fmt.Errorf("Unknown database type: %s", Database.Type)
129+
return "", fmt.Errorf("unknown database type: %s", Database.Type)
140130
}
141131

142132
return connStr, nil

options/locale/locale_en-US.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,9 @@ host = Host
197197
user = Username
198198
password = Password
199199
db_name = Database Name
200-
db_helper = Note to MySQL users: please use the InnoDB storage engine and if you use "utf8mb4", your InnoDB version must be greater than 5.6 .
201200
db_schema = Schema
202201
db_schema_helper = Leave blank for database default ("public").
203202
ssl_mode = SSL
204-
charset = Charset
205203
path = Path
206204
sqlite_helper = File path for the SQLite3 database.<br>Enter an absolute path if you run Gitea as a service.
207205
reinstall_error = You are trying to install into an existing Gitea database

routers/install/install.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ func Install(ctx *context.Context) {
9999
form.DbName = setting.Database.Name
100100
form.DbPath = setting.Database.Path
101101
form.DbSchema = setting.Database.Schema
102-
form.Charset = setting.Database.Charset
103102

104103
curDBType := setting.Database.Type.String()
105104
var isCurDBTypeSupported bool
@@ -269,7 +268,6 @@ func SubmitInstall(ctx *context.Context) {
269268
setting.Database.Name = form.DbName
270269
setting.Database.Schema = form.DbSchema
271270
setting.Database.SSLMode = form.SSLMode
272-
setting.Database.Charset = form.Charset
273271
setting.Database.Path = form.DbPath
274272
setting.Database.LogSQL = !setting.IsProd
275273

@@ -388,7 +386,6 @@ func SubmitInstall(ctx *context.Context) {
388386
cfg.Section("database").Key("PASSWD").SetValue(setting.Database.Passwd)
389387
cfg.Section("database").Key("SCHEMA").SetValue(setting.Database.Schema)
390388
cfg.Section("database").Key("SSL_MODE").SetValue(setting.Database.SSLMode)
391-
cfg.Section("database").Key("CHARSET").SetValue(setting.Database.Charset)
392389
cfg.Section("database").Key("PATH").SetValue(setting.Database.Path)
393390
cfg.Section("database").Key("LOG_SQL").SetValue("false") // LOG_SQL is rarely helpful
394391

services/forms/user_form.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ type InstallForm struct {
2727
DbPasswd string
2828
DbName string
2929
SSLMode string
30-
Charset string `binding:"Required;In(utf8,utf8mb4)"`
3130
DbPath string
3231
DbSchema string
3332

templates/install.tmpl

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
<div class="inline required field {{if .Err_DbSetting}}error{{end}}">
4545
<label for="db_name">{{.locale.Tr "install.db_name"}}</label>
4646
<input id="db_name" name="db_name" value="{{.db_name}}">
47-
<span class="help">{{.locale.Tr "install.db_helper"}}</span>
4847
</div>
4948
</div>
5049

@@ -69,20 +68,6 @@
6968
</div>
7069
</div>
7170

72-
<div class="gt-hidden" data-db-setting-for="mysql">
73-
<div class="inline required field">
74-
<label>{{.locale.Tr "install.charset"}}</label>
75-
<div class="ui selection database type dropdown">
76-
<input type="hidden" name="charset" value="{{if .charset}}{{.charset}}{{else}}utf8mb4{{end}}">
77-
<div class="default text">utf8mb4</div>
78-
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
79-
<div class="menu">
80-
<div class="item" data-value="utf8mb4">utf8mb4</div>
81-
</div>
82-
</div>
83-
</div>
84-
</div>
85-
8671
<div class="gt-hidden" data-db-setting-for="sqlite3">
8772
<div class="inline required field {{if or .Err_DbPath .Err_DbSetting}}error{{end}}">
8873
<label for="db_path">{{.locale.Tr "install.path"}}</label>

0 commit comments

Comments
 (0)