gitea升级后报错解决

当前版本gitea 1.8 由于不支持katex,决定升级到gitea1.24。不过升级后,打开网页点击首页内容报500错误。

错误提示为

发生了一个错误;
SyncRepoBranches, Error 1366 (22007):Incorrect string value: '\xE8\xA7\xA3\xE5\x86\xB3...' for column `dbnamo`. `branch` `commit_message` at row 1

看到\x样的字符,第一反应是字符编码的问题,错误信息提到表branch 的字段commit_message,初步判断是该表的字符集有问题,修改字符集即可。

1、查看gitea官方文档,查看字符集要求如下:

使用 UTF-8 字符集和大小写敏感的排序规则创建数据库。

utf8mb4_bin 是 MySQL/MariaDB 的通用排序规则。 Gitea 启动后会尝试把数据库修改为更合适的字符集 (utf8mb4_0900_as_cs 或者 uca1400_as_cs) 并在可能的情况下更改数据库。 如果你想指定自己的字符集规则,可以在 app.ini 中设置 [database].CHARSET_COLLATION

CREATE DATABASE giteadb CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_bin';


2、查看和修改数据库编码
show variables like '%char%';
+--------------------------+----------------------------+
| Variable_name            | Value                      |
+--------------------------+----------------------------+
| character_set_client     | utf8mb4                    |
| character_set_connection | utf8mb4                    |
| character_set_database   | latin1                     |
| character_set_filesystem | binary                     |
| character_set_results    | utf8mb4                    |
| character_set_server     | utf8mb4                    |
| character_set_system     | utf8                       |
| character_sets_dir       | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
数据库字符集应该正常,检查一下报错的branch表编码。
show full columns from branch;
+----------------+--------------+-------------------+------+-----+---------+----------------+---------------------------------+---------+
| Field          | Type         | Collation         | Null | Key | Default | Extra          | Privileges                      | Comment |
+----------------+--------------+-------------------+------+-----+---------+----------------+---------------------------------+---------+
| id             | bigint(20)   | NULL              | NO   | PRI | NULL    | auto_increment | select,insert,update,references |         |
| repo_id        | bigint(20)   | NULL              | YES  | MUL | NULL    |                | select,insert,update,references |         |
| name           | varchar(255) | latin1_swedish_ci | NO   |     | NULL    |                | select,insert,update,references |         |
| commit_id      | varchar(255) | latin1_swedish_ci | YES  |     | NULL    |                | select,insert,update,references |         |
| commit_message | text         | latin1_swedish_ci | YES  |     | NULL    |                | select,insert,update,references |         |
| pusher_id      | bigint(20)   | NULL              | YES  |     | NULL    |                | select,insert,update,references |         |
| is_deleted     | tinyint(1)   | NULL              | YES  | MUL | NULL    |                | select,insert,update,references |         |
| deleted_by_id  | bigint(20)   | NULL              | YES  |     | NULL    |                | select,insert,update,references |         |
| deleted_unix   | bigint(20)   | NULL              | YES  | MUL | NULL    |                | select,insert,update,references |         |
| commit_time    | bigint(20)   | NULL              | YES  |     | NULL    |                | select,insert,update,references |         |
| created_unix   | bigint(20)   | NULL              | YES  |     | NULL    |                | select,insert,update,references |         |
| updated_unix   | bigint(20)   | NULL              | YES  |     | NULL    |                | select,insert,update,references |         |
+----------------+--------------+-------------------+------+-----+---------+----------------+---------------------------------+---------+

修改表的字符集
ALTER TABLE branch CONVERT TO CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_bin';
再次查看字符集,已经修改成功。
show full columns from branch;
+----------------+--------------+-------------+------+-----+---------+----------------+---------------------------------+---------+
| Field          | Type         | Collation   | Null | Key | Default | Extra          | Privileges                      | Comment |
+----------------+--------------+-------------+------+-----+---------+----------------+---------------------------------+---------+
| id             | bigint(20)   | NULL        | NO   | PRI | NULL    | auto_increment | select,insert,update,references |         |
| repo_id        | bigint(20)   | NULL        | YES  | MUL | NULL    |                | select,insert,update,references |         |
| name           | varchar(255) | utf8mb4_bin | NO   |     | NULL    |                | select,insert,update,references |         |
| commit_id      | varchar(255) | utf8mb4_bin | YES  |     | NULL    |                | select,insert,update,references |         |
| commit_message | mediumtext   | utf8mb4_bin | YES  |     | NULL    |                | select,insert,update,references |         |
| pusher_id      | bigint(20)   | NULL        | YES  |     | NULL    |                | select,insert,update,references |         |
| is_deleted     | tinyint(1)   | NULL        | YES  | MUL | NULL    |                | select,insert,update,references |         |
| deleted_by_id  | bigint(20)   | NULL        | YES  |     | NULL    |                | select,insert,update,references |         |
| deleted_unix   | bigint(20)   | NULL        | YES  | MUL | NULL    |                | select,insert,update,references |         |
| commit_time    | bigint(20)   | NULL        | YES  |     | NULL    |                | select,insert,update,references |         |
| created_unix   | bigint(20)   | NULL        | YES  |     | NULL    |                | select,insert,update,references |         |
| updated_unix   | bigint(20)   | NULL        | YES  |     | NULL    |                | select,insert,update,references |         |
+----------------+--------------+-------------+------+-----+---------+----------------+---------------------------------+---------+



3、重新启动应用,正常。
百度大模型

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

腾讯云图